Skip to content

Commit ae73269

Browse files
committed
maximum subarray solution
1 parent 45ff2a2 commit ae73269

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

maximum-subarray/devyejin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def maxSubArray(self, nums: list[int]) -> int:
3+
dp = [0] * len(nums)
4+
dp[0] = nums[0]
5+
6+
for i in range(1, len(nums)):
7+
dp[i] = max(nums[i], dp[i - 1] + nums[i])
8+
9+
return max(dp)
10+

0 commit comments

Comments
 (0)