You are viewing a single comment's thread. Return to all comments →
Java
public static List<Integer> maxSubarray(List<Integer> arr) { int sum = arr.get(0); int maxSubSum = sum; int sumSequences = sum; for(int i = 1; i<arr.size(); i++){ int number =arr.get(i); sum =Math.max(sum+number, number); maxSubSum = Math.max(maxSubSum, sum); if(sumSequences<0){ sumSequences = Math.max(number, sumSequences); }else{ sumSequences += Math.max(0, number); } } return Arrays.asList(maxSubSum, sumSequences); }
Seems like cookies are disabled on this browser, please enable them to open this website
The Maximum Subarray
You are viewing a single comment's thread. Return to all comments →
Java