Created
July 2, 2019 12:08
-
-
Save Desolve/37fa93e5c41056d82306906bee93ad2d to your computer and use it in GitHub Desktop.
0053 Maximum Subarray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def maxSubArray(self, nums: 'List[int]') -> 'int': | |
l = len(nums) | |
if l == 0: return 0 | |
res = now = nums[0] | |
for i in range(1, l): | |
if now > 0: | |
now += nums[i] | |
else: | |
now = nums[i] | |
if now > res: | |
res = now | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment