LC053 - Maximum Subarray
Last updated
Last updated
def maxSubArray(self, nums: List[int]): -> int:
ptr = 0
tally = 0
maxSub = nums[0]
while ptr < len(nums):
if tally < 0:
tally = 0
tally += nums[ptr]
maxSub = max(maxSub, tally)
ptr += 1
return maxSub