Skip to content

Commit 3c2f0b0

Browse files
committed
[main] house-robber solution
1 parent a9593e8 commit 3c2f0b0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

house-robber/jeongyunjae.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def rob(self, nums: List[int]) -> int:
3+
result = list(nums)
4+
5+
for i, data in enumerate(result):
6+
if i <= 1:
7+
continue
8+
9+
stolen_money = result[i]
10+
before_house_money = result[i-1]
11+
12+
for j in range(i-1):
13+
if result[i] + result[j] > stolen_money:
14+
stolen_money = result[i] + result[j]
15+
16+
result[i] = max(before_house_money, stolen_money)
17+
18+
return max(result)

0 commit comments

Comments
 (0)