Created
July 2, 2019 12:08
-
-
Save Desolve/7847030300839993b7b6f7cbf723ded2 to your computer and use it in GitHub Desktop.
0053 Maximum Subarray
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
class Solution { | |
public int maxSubArray(int[] nums) { | |
int res = nums[0]; | |
int curr = nums[0]; | |
for(int i = 1; i < nums.length; i++) { | |
curr += nums[i]; | |
if (curr < 0 || nums[i] > curr) | |
curr = nums[i]; | |
if (res < curr) | |
res = curr; | |
} | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment