Skip to content

Commit fdf3120

Browse files
committed
feat(soobing): maximum-subarray
1 parent 607512f commit fdf3120

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

maximum-subarray/soobing.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function maxSubArray(nums: number[]): number {
2+
let currentSum = nums[0];
3+
let maxSum = nums[0];
4+
for (let i = 1; i < nums.length; i++) {
5+
currentSum = Math.max(nums[i], currentSum + nums[i]);
6+
maxSum = Math.max(maxSum, currentSum);
7+
}
8+
return maxSum;
9+
}

0 commit comments

Comments
 (0)