Skip to content

Commit 99ec887

Browse files
committed
solve : maximum subarray
1 parent 435e438 commit 99ec887

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

maximum-subarray/samthekorean.py

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

0 commit comments

Comments
 (0)