Skip to content

Commit 6a2d333

Browse files
Solve : Maximum Subarray
1 parent e64125a commit 6a2d333

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

maximum-subarray/printjin-gmailcom.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def maxSubArray(self, nums):
3+
max_sum = current_sum = nums[0]
4+
for num in nums[1:]:
5+
current_sum = max(num, current_sum + num)
6+
max_sum = max(max_sum, current_sum)
7+
return max_sum

0 commit comments

Comments
 (0)