Maximum Subarray LeetCode solution in Java

1
class Solution {
2
public int maxSubArray(int[] nums) {
3
int n = nums.length;
4
int currmax = 0;
5
int gmax = nums[0];
6
for (int i = 0; i < n; i++) {
7
currmax += nums[i];
8
gmax = Math.max(gmax, currmax);
9
currmax = Math.max(currmax, 0);
10
}
11
return gmax;
12
}
13
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0