Skip to content

Commit 375f0eb

Browse files
committed
maximum subarray solution
1 parent ac4ef44 commit 375f0eb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def maxSubArray(self, nums: List[int]) -> int:
3+
n = len(nums)
4+
5+
# ์›๋ž˜๋ผ๋ฉด dp ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด, i๋ฒˆ์งธ ์›์†Œ๊นŒ์ง€ ํƒ์ƒ‰ํ•œ ๊ฒฐ๊ณผ ์ค‘ ์ตœ๋Œ“๊ฐ’์„ ๊ฐ๊ฐ์˜ ์ธ๋ฑ์Šค์— ์ €์žฅ
6+
# ํ•˜์ง€๋งŒ ์ง€๊ธˆ์€ ์ตœ๋Œ“๊ฐ’๋งŒ ๋‚จ๊ธฐ๋ฉด ๋˜๋ฏ€๋กœ ์ผ์ฐจ์  ์ตœ์ ํ™”
7+
current = nums[0]
8+
result = nums[0]
9+
10+
for i in range(1, len(nums)):
11+
current = max(current + nums[i], nums[i])
12+
result = max(result, current)
13+
14+
return result

0 commit comments

Comments
ย (0)