class Solution:
# @param A, a list of integers
# @return an integer
# 6:57
def maxSubArray(self, A):
if not A:
return 0
curSum = maxSum = A[0]
for num in A[1:]:
curSum = max(num, curSum + num)
maxSum = max(maxSum, curSum)
return maxSum
A Python solution


A little revision to avoid copying the list.
class Solution(object): def maxSubArray(self, nums): """ :type nums: List[int] :rtype: int """ if not nums: return 0 maxSum = currentSum = float("inf") for n in nums: currentSum = max(currentSum+n, n) maxSum = max(maxSum, currentSum) return maxSum