Python: O(N) 6 lines


  • 0
    A
    class Solution(object):
    def maxSubArray(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        result, sum_v = nums[0], 0
        for i, v in enumerate(nums):
            sum_v += v
            if result < sum_v: result = sum_v
            if sum_v < 0: sum_v = 0
        return result

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.