Python O(n)


  • 0
    A

    This solution have time complexity of O(n) and space complexity of O(1)

        def maxSubArray(self, nums):
            if not nums:
                return 0
            pivotSum = maxSum = nums[0]
            for num in nums[1:]:
                pivotSum = max(num, num+pivotSum)
                maxSum = max(maxSum, pivotSum)
            return maxSum
            """
            :type nums: List[int]
            :rtype: int```

Log in to reply
 

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