Skip to content

Commit 6c6a87c

Browse files
committed
solve: max sub array
1 parent fb1b9b7 commit 6c6a87c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

maximum-subarray/evan.py

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

0 commit comments

Comments
 (0)