Created
January 13, 2018 07:21
-
-
Save gauravbansal74/77754ec01c58b053a0cbd3ab7a676ca2 to your computer and use it in GitHub Desktop.
max_slice
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
// you can also use imports, for example: | |
import java.util.*; | |
// you can write to stdout for debugging purposes, e.g. | |
// System.out.println("this is a debug message"); | |
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
int len = A.length; | |
int largest = A[0]; | |
int last = largest; | |
for(int i=1;i<len;i++) { | |
last = Math.max(A[i],A[i]+last); | |
if(last>largest){ | |
largest = last; | |
} | |
} | |
return largest; | |
} | |
}max_slice |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment