Last active
April 3, 2020 18:41
-
-
Save munguial/ec304e2fe29c903e7ad3913ce66c3afb to your computer and use it in GitHub Desktop.
Day 3 - 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
# 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