Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
Created May 2, 2015 16:54
Show Gist options
  • Save stephen-maina/dec3f092bbecce428d7f to your computer and use it in GitHub Desktop.
Save stephen-maina/dec3f092bbecce428d7f to your computer and use it in GitHub Desktop.
had to research
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