(int[] nums)
| 1 | class Solution { |
| 2 | public int maxAbsoluteSum(int[] nums) { |
| 3 | int maxSum = Integer.MIN_VALUE; |
| 4 | int minSum = Integer.MAX_VALUE; |
| 5 | int curPSum=0; |
| 6 | int curNSum=0; |
| 7 | for(int num : nums){ |
| 8 | // pos |
| 9 | curPSum += num; |
| 10 | maxSum = Math.max(maxSum,curPSum); |
| 11 | if(curPSum < 0){ |
| 12 | curPSum = 0; |
| 13 | } |
| 14 | // neg |
| 15 | curNSum += num; |
| 16 | minSum = Math.min(minSum,curNSum); |
| 17 | if(curNSum > 0){ |
| 18 | curNSum = 0; |
| 19 | } |
| 20 | } |
| 21 | return Math.max(maxSum, Math.abs(minSum)); |
| 22 | } |
| 23 | } |
nothing calls this directly
no outgoing calls
no test coverage detected