1 public class Solution { 2 public int maxSubArray(int[] A) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int result = Integer.MIN_VALUE; 6 int curSum = 0; 7 for(int i = 0; i < A.length; i++){ 8 curSum += A[i]; 9 if(curSum > result){ 10 result = curSum; 11 } 12 if(curSum < 0){ 13 curSum = 0; 14 } 15 } 16 17 return result; 18 } 19 }