Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

maximum subarray solution leetcode

def approach3(nums):
    ans = nums[0]
    subarr_sum = nums[0]

    for i in range(1, len(nums)):
        subarr_sum = max(nums[i], nums[i] + subarr_sum)
        ans = max(ans, subarr_sum)

    return ans
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #maximum #subarray #solution #leetcode
ADD COMMENT
Topic
Name
9+1 =