Skip to content

Commit 91c1722

Browse files
committed
add: maximumSubArray solution
1 parent ddddb86 commit 91c1722

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

maximum-subarray/Cyjin-jani.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! 다시 풀어보기 (divide and conquer)
2+
const maxSubArray = function (nums) {
3+
let currentSum = 0;
4+
let maxSum = -Infinity;
5+
6+
for (let right = 0; right < nums.length; right++) {
7+
currentSum += nums[right];
8+
maxSum = Math.max(maxSum, currentSum);
9+
if (currentSum < 0) currentSum = 0;
10+
}
11+
12+
return maxSum;
13+
};

0 commit comments

Comments
 (0)