Skip to content

Commit c5ea174

Browse files
committed
Time: 1 ms (85.57%), Space: 57.3 MB (92.55%) - LeetHub
1 parent 43a7508 commit c5ea174

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var maxSubArray = function (nums) {
6+
let right = 0;
7+
let total = -Infinity;
8+
let curSum = 0;
9+
while (right < nums.length) {
10+
curSum += nums[right];
11+
curSum = Math.max(nums[right], curSum);
12+
total = Math.max(total, curSum);
13+
right++;
14+
}
15+
return total;
16+
};

0 commit comments

Comments
 (0)