Skip to content

Commit b2d5a03

Browse files
authored
Added Python solution for 53. Maximum Subarray (Tahanima#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)