Python 6 line answer


  • 0
    class Solution(object):
        def maxSubArray(self, nums):
            if not nums:return 0
            maxsum=sum=nums[0]
            for num in nums[1:]:
                sum=(num,sum+num)[sum>0]
                maxsum=max(maxsum,sum)
            return maxsum
    

Log in to reply
 

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