Skip to content

Commit 6c2971e

Browse files
committed
maximum-subarray solution
1 parent 7c7bcc9 commit 6c2971e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

maximum-subarray/ohkingtaek.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def maxSubArray(self, nums: List[int]) -> int:
3+
"""
4+
현재까지 이어서 만든 부분합이 음수면 버리고 다시 시작하여 갱신 하는 것입니다.
5+
"""
6+
now_sum = nums[0]
7+
max_sum = nums[0]
8+
9+
for num in nums[1:]:
10+
now_sum = max(num, now_sum + num)
11+
max_sum = max(max_sum, now_sum)
12+
return max_sum
13+

0 commit comments

Comments
 (0)