Skip to content

Commit 84c1a0e

Browse files
author
sejineer
committed
maximum-subarray solution
1 parent 53fe546 commit 84c1a0e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

maximum-subarray/sejineer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
시간 복잡도 O(N)
3+
공간 복잡도 O(N)
4+
"""
5+
class Solution:
6+
def maxSubArray(self, nums: List[int]) -> int:
7+
dp = [0] * len(nums)
8+
dp[0] = nums[0]
9+
10+
for i in range(1, len(nums)):
11+
dp[i] = max(nums[i], dp[i - 1] + nums[i])
12+
13+
return max(dp)

0 commit comments

Comments
 (0)