Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Maximum Subarray sum

 def maxSubArray(self, nums: List[int]) -> int:
        curr_best = overall_best =  nums[0]
        for i in range(1,len(nums)):
            if curr_best>=0:
                curr_best = curr_best + nums[i]
            else:
                curr_best = nums[i]
            if curr_best > overall_best:
                overall_best = curr_best
        return overall_best
 
PREVIOUS NEXT
Tagged: #Maximum #Subarray #sum
ADD COMMENT
Topic
Name
5+1 =