Skip to content

Commit 7a6e480

Browse files
committed
maximum-subarray solved
1 parent 8377a00 commit 7a6e480

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

maximum-subarray/hsskey.js

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

0 commit comments

Comments
 (0)