Skip to content

Commit 34c8ea2

Browse files
add solution 053[js]
1 parent 229181c commit 34c8ea2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const maxSubArray = function(nums){
2+
if(nums.length === 0) return 0;
3+
let ans = nums[0], tmp = nums[0];
4+
for(let i = 1; i < nums.length; i++){
5+
tmp = Math.max(tmp+nums[i], nums[i]);
6+
ans = Math.max(ans,tmp);
7+
}
8+
return ans;
9+
}

0 commit comments

Comments
 (0)