Skip to content

Commit f81de76

Browse files
committed
maximum-subarray solution
1 parent 8286332 commit f81de76

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

maximum-subarray/yuhyeon99.js

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

0 commit comments

Comments
 (0)