Problem · Array
Maximum Subarray Sum
Learn this problemProblem statement
You are given an integer array nums. Find the 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.