Skip to content

Commit

Permalink
Time: 91 ms (81.88%), Space: 50.6 MB (35.18%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
rldnrl committed Dec 30, 2022
1 parent 1fd7f2e commit 3c9fd0a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 0053-maximum-subarray/0053-maximum-subarray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @param {number[]} nums
* @return {number}
*/
var maxSubArray = function(nums) {
let answer = nums[0];
let curSum = 0;

for (const num of nums) {
if (curSum < 0) {
curSum = 0;
}
curSum += num;
answer = Math.max(answer, curSum);
}

return answer;
};

0 comments on commit 3c9fd0a

Please sign in to comment.