Skip to content

Commit b07453c

Browse files
committed
Maximum Subarray
1 parent e0d1897 commit b07453c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

maximum-subarray/jihyeon.js

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 maxSum = nums[0];
7+
let max = nums[0];
8+
9+
for (let i = 1; i < nums.length; i++) {
10+
max = Math.max(nums[i], max + nums[i]);
11+
maxSum = Math.max(max, maxSum);
12+
}
13+
return maxSum;
14+
};

0 commit comments

Comments
 (0)