Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created March 7, 2020 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/6beb3001e2e61f01d5d2ed9cd62d72fb to your computer and use it in GitHub Desktop.
Save deque-blog/6beb3001e2e61f01d5d2ed9cd62d72fb to your computer and use it in GitHub Desktop.
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