Created
March 7, 2020 09:15
-
-
Save deque-blog/6beb3001e2e61f01d5d2ed9cd62d72fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def maxSubArray(nums: List[int]) -> int: | |
max_sum = float('-inf') | |
cum_sum = 0 | |
for num in nums: | |
cum_sum += num | |
if cum_sum >= max_sum: | |
max_sum = cum_sum | |
if cum_sum <= 0: | |
cum_sum = 0 | |
return max_sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment