Skip to content

Commit 832aa5d

Browse files
committed
maxSubArray
1 parent 9ef8249 commit 832aa5d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

maxSubArray.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var maxSubArray = function(nums) {
6+
let start = 0,
7+
total = -(Number.MAX_SAFE_INTEGER)
8+
9+
while(nums.length){
10+
let subtotal = 0;
11+
for (let x = start; x < nums.length; x++){
12+
subtotal += nums[x]
13+
if (subtotal > total){
14+
total = subtotal
15+
}
16+
}
17+
18+
nums.shift();
19+
}
20+
21+
return total
22+
23+
};

0 commit comments

Comments
 (0)