Skip to content

Instantly share code, notes, and snippets.

@rohanjai777
Created April 21, 2021 03:37
Show Gist options
  • Save rohanjai777/8fb2f8604072ca2d33157df776c665e4 to your computer and use it in GitHub Desktop.
Save rohanjai777/8fb2f8604072ca2d33157df776c665e4 to your computer and use it in GitHub Desktop.
public int maxSubArray(final int[] arr) {
if(arr.length == 0){
return -1;
}
int max = 0;
int finalmax = Integer.MIN_VALUE;
for(int i=0;i<arr.length;i++){
max = Math.max(max+arr[i],arr[i]);
finalmax = Math.max(max,finalmax);
}
return finalmax;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment