Created
May 2, 2015 16:54
-
-
Save stephen-maina/dec3f092bbecce428d7f to your computer and use it in GitHub Desktop.
had to research
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 solution(int[] A) { | |
int ans = A[0]; | |
int sum = 0; | |
for (int i = 0; i < A.length; i++) { | |
if (sum > 0) { | |
sum += A[i]; | |
} else { | |
sum = A[i]; | |
} | |
ans = Math.max(ans, sum); | |
} | |
return ans; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment