MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / maxSubArray

Function maxSubArray

53-maximum-subarray/maximum-subarray.js:7–19  ·  view source on GitHub ↗
(nums)

Source from the content-addressed store, hash-verified

5 * @return {number}
6 */
7var maxSubArray = function(nums) {
8 let maxCurrent = nums[0];
9 let maxGlobal = nums[0];
10
11 for (let i = 1; i < nums.length; i++) {
12 maxCurrent = Math.max(nums[i], maxCurrent + nums[i]);
13 if (maxCurrent > maxGlobal) {
14 maxGlobal = maxCurrent;
15 }
16 }
17
18 return maxGlobal;
19};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected