Skip to content

Instantly share code, notes, and snippets.

@munguial
Last active April 3, 2020 18:41
Show Gist options
  • Save munguial/ec304e2fe29c903e7ad3913ce66c3afb to your computer and use it in GitHub Desktop.
Save munguial/ec304e2fe29c903e7ad3913ce66c3afb to your computer and use it in GitHub Desktop.
Day 3 - Maximum subarray
# https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3285/
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
maxi = nums[0]
tempSum = nums[0]
for n in nums[1:]:
if tempSum < 0:
tempSum = n
else:
tempSum += n
maxi = max(maxi, tempSum)
return maxi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment