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

Method maxSubArray

53-maximum-subarray/maximum-subarray.java:4–16  ·  view source on GitHub ↗
(int[] nums)

Source from the content-addressed store, hash-verified

2
3class Solution {
4 public int maxSubArray(int[] nums) {
5 int maxCurrent = nums[0];
6 int maxGlobal = nums[0];
7
8 for (int i = 1; i < nums.length; i++) {
9 maxCurrent = Math.max(nums[i], maxCurrent + nums[i]);
10 if (maxCurrent > maxGlobal) {
11 maxGlobal = maxCurrent;
12 }
13 }
14
15 return maxGlobal;
16 }
17}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected