Skip to content

Instantly share code, notes, and snippets.

@gauravbansal74
Created January 13, 2018 07:21
Show Gist options
  • Save gauravbansal74/77754ec01c58b053a0cbd3ab7a676ca2 to your computer and use it in GitHub Desktop.
Save gauravbansal74/77754ec01c58b053a0cbd3ab7a676ca2 to your computer and use it in GitHub Desktop.
max_slice
// 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