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

@Google I had the same solution; the
if not A: return 0
edge case is actually not needed to make the tests pass, since it is given in the question that the array should have at least one number.