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 3bdc80f commit 065acb2Copy full SHA for 065acb2
maximum-subarray/devyejin.py
@@ -1,10 +1,11 @@
1
class Solution:
2
def maxSubArray(self, nums: list[int]) -> int:
3
- dp = [0] * len(nums)
4
- dp[0] = nums[0]
+ current_sum = nums[0]
+ max_sum = nums[0]
5
6
for i in range(1, len(nums)):
7
- dp[i] = max(nums[i], dp[i - 1] + nums[i])
+ current_sum = max(nums[i], current_sum + nums[i])
8
+ max_sum = max(current_sum, max_sum)
9
- return max(dp)
10
+ return max_sum
11
0 commit comments