We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fbb378c commit a70e1b4Copy full SHA for a70e1b4
0053-maximum-subarray/solution.py
@@ -1,14 +1,15 @@
1
-# Approach 2 - Dynamic Programming
+# Approach 2: Dynamic Programming
2
3
-# Time: O(N)
+# Time: O(n)
4
# Space: O(1)
5
6
class Solution:
7
def maxSubArray(self, nums: List[int]) -> int:
8
current_subarray = max_subarray = nums[0]
9
-
+
10
for num in nums[1:]:
11
- current_subarray = max(current_subarray + num, num)
+ current_subarray = max(num, current_subarray + num)
12
max_subarray = max(max_subarray, current_subarray)
13
14
return max_subarray
15
0 commit comments