Skip to content

Commit b74f6ce

Browse files
committed
house robber solution & added newline
1 parent 1de52da commit b74f6ce

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

house-robber/yayyz.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def rob(self, nums: List[int]) -> int:
3+
n = len(nums)
4+
5+
if n == 1:
6+
return nums[0]
7+
8+
dp = [0] * n
9+
dp[0] = nums[0]
10+
dp[1] = max(nums[0], nums[1])
11+
12+
# i 번째를 털지 않은 조건과 i번째를 털은 조건 중 max를 비교
13+
for i in range(2, n):
14+
dp[i] = max(dp[i-1], dp[i-2] + nums[i])
15+
16+
return dp[-1]
17+

longest-consecutive-sequence/yayyz.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ def longestConsecutive(self, nums: List[int]) -> int:
1919
lastNum = nums[i]
2020

2121
return result
22+
23+
2224

0 commit comments

Comments
 (0)