Problem · Array
Maximum Subarray
Learn this problemProblem statement
You are given an integer array nums. Find the non-empty contiguous subarray with the largest sum and return that sum.
Function
maxSubArray(nums: int[]) → intExamples
Example 1
nums = [-2,1,-3,4,-1,2,1,-5,4]return = 6The best contiguous subarray is [4,-1,2,1], whose sum is 6.
Constraints
1 <= nums.length <= 100000-10000 <= nums[i] <= 10000- The answer fits in a signed 32-bit integer.