Skip to content

Instantly share code, notes, and snippets.

@robotron2084
Created March 3, 2020 02:34
Show Gist options
  • Save robotron2084/a7d2571384304461cb80ddd52269afd9 to your computer and use it in GitHub Desktop.
Save robotron2084/a7d2571384304461cb80ddd52269afd9 to your computer and use it in GitHub Desktop.
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
solutions = []
bestSolution = -sys.maxsize - 1
for i in range(0, len(nums)):
num = nums[i]
prevSolution = 0
if(i > 0):
prevSolution = solutions[i - 1]
if(prevSolution + num > num):
solutions.append(prevSolution + num)
else:
solutions.append(num)
if(solutions[i] > bestSolution):
bestSolution = solutions[i]
return bestSolution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment