Skip to content

Commit f51f99f

Browse files
committedMay 17, 2022
Time: 95 ms (68.41%), Space: 50.2 MB (82.25%) - LeetHub
1 parent ef00060 commit f51f99f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var maxSubArray = function(nums) {
6+
let sum= nums[0] ;
7+
let max =nums[0];
8+
for (let i = 1; i<nums.length;i++){
9+
sum = Math.max(sum+=nums[i],nums[i]);
10+
max = Math.max(sum,max)
11+
}
12+
13+
return max
14+
};

0 commit comments

Comments
 (0)