Skip to content

Commit a70e1b4

Browse files
committed
Sync LeetCode submission Runtime - 86 ms (37.55%), Memory - 31.5 MB (85.17%)
1 parent fbb378c commit a70e1b4

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

0053-maximum-subarray/solution.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
# Approach 2 - Dynamic Programming
1+
# Approach 2: Dynamic Programming
22

3-
# Time: O(N)
3+
# Time: O(n)
44
# Space: O(1)
55

66
class Solution:
77
def maxSubArray(self, nums: List[int]) -> int:
88
current_subarray = max_subarray = nums[0]
9-
9+
1010
for num in nums[1:]:
11-
current_subarray = max(current_subarray + num, num)
11+
current_subarray = max(num, current_subarray + num)
1212
max_subarray = max(max_subarray, current_subarray)
13-
13+
1414
return max_subarray
15+

0 commit comments

Comments
 (0)