Created
March 2, 2015 04:09
-
-
Save dmnugent80/d67c20879017e01fabeb to your computer and use it in GitHub Desktop.
Maximum Subarray
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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