Skip to content

Instantly share code, notes, and snippets.

@dmnugent80
Created March 2, 2015 04:09
Show Gist options
  • Save dmnugent80/d67c20879017e01fabeb to your computer and use it in GitHub Desktop.
Save dmnugent80/d67c20879017e01fabeb to your computer and use it in GitHub Desktop.
Maximum Subarray
public class Solution {
public int maxSubArray(int[] A) {
int maxSoFar = A[0];
int sumSoFar = A[0];
for (int i = 1; i < A.length; i++){
sumSoFar = sumSoFar + A[i];
sumSoFar = Math.max(sumSoFar, A[i]);
maxSoFar = Math.max(sumSoFar, maxSoFar);
}
return maxSoFar;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment