Skip to content

Instantly share code, notes, and snippets.

@Desolve
Created July 2, 2019 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Desolve/7847030300839993b7b6f7cbf723ded2 to your computer and use it in GitHub Desktop.
Save Desolve/7847030300839993b7b6f7cbf723ded2 to your computer and use it in GitHub Desktop.
0053 Maximum Subarray
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