Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b2d5a03

Browse files
Added Python solution for 53. Maximum Subarray (#117)
* Added Python solution for 53. MaximumSubarray * Changes added to Python solution for 53. MaximumSubarray * Changes added to Python solution for 53. MaximumSubarray
1 parent d357891 commit b2d5a03

File tree

1 file changed

+12
-0
lines changed

1 file changed

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /