Created
April 21, 2021 03:37
-
-
Save rohanjai777/8fb2f8604072ca2d33157df776c665e4 to your computer and use it in GitHub Desktop.
This file contains 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 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