Python solution o(n) beat 99.94% other solutions


  • 0
    S
    class Solution(object):
        def maxSubArray(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            maxs = 0
            maxg = 0
            for num in nums:
                maxs = 0 if maxs+num<0 else maxs+num
                maxg = maxs if maxs>maxg else maxg
            if maxg == 0:
                return max(nums)
            else:
                return maxg
    

Log in to reply
 

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