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