Skip to content

Commit

Permalink
feat: problem 53
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin-nair98 committed Feb 10, 2024
1 parent 765754d commit 5375ac8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 53_Maximum Subarray/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
maxSum = float('-inf')
store = [0] * len(nums)
store[0] = max(0, nums[0])
maxSum = max(maxSum, nums[0])
for i in range(1, len(nums)):
store[i] = store[i-1] + nums[i]
maxSum = max(store[i], maxSum)
store[i] = max(0, store[i])
return maxSum

0 comments on commit 5375ac8

Please sign in to comment.