Skip to content

Commit 94ee1a8

Browse files
committed
53. Maximum Subarray Solution
1 parent 810bbf6 commit 94ee1a8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

maximum-subarray/doh6077.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def maxSubArray(self, nums: List[int]) -> int:
3+
res = nums[0]
4+
total = 0
5+
6+
for n in nums:
7+
if total < 0:
8+
total = 0
9+
10+
total += n
11+
res = max(res, total)
12+
13+
return res

0 commit comments

Comments
 (0)