O(n) Python


  • 0
    H
    class Solution(object):
        def maxSubArray(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            temp = 0
            maxSum = -2147483648
            for num in nums:
                temp = max(temp + num, num)
                maxSum = max(temp, maxSum)
            return maxSum
    

Log in to reply
 

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