Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int maxSubarraySum(int[] arr) {
- int maxSum = Integer.MIN_VALUE;
- int curSum = 0;
- for(int el: arr) {
- curSum += el;
- maxSum = Math.max(maxSum, curSum);
- if(curSum < 0) {
- curSum = 0;
- }
- }
- return maxSum;
- }
Advertisement
Add Comment
Please, Sign In to add comment