Skip to content

Commit ca4e9aa

Browse files
Create 53. Maximum Subarray
1 parent 3e0e7e6 commit ca4e9aa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def maxSubArray(self, nums: List[int]) -> int:
3+
max_sum = -100001
4+
temp_sum = 0
5+
for i in range(len(nums)):
6+
temp_sum += nums[i]
7+
if temp_sum >= max_sum:
8+
max_sum = temp_sum
9+
if temp_sum < 0: #if -ve, start from next num cuz if we continue adding, there is no use bruh....
10+
temp_sum = 0
11+
return max_sum

0 commit comments

Comments
 (0)