Maximum Subarray
Return the largest sum of a nonempty contiguous subarray.
Example 1
nums = [-3,4,-1,2,-5]5Explanation
Contiguous 4,-1,2 sums to 5; dropping the surrounding negatives is best.
Example 2
nums = [-7,-2,-9]-2Explanation
The subarray must be nonempty, so choose -2 rather than zero.
Example 3
nums = [5]5Explanation
The only nonempty subarray contains 5.
Constraints
- 1 <= len(nums) <= 100000
- Values are -10000..10000
Function contract
maxSubArrayArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[-3,4,-1,2,-5]