Skip to content

Commit 90317bd

Browse files
solves house robber in python
1 parent b534f3b commit 90317bd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RotateArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/rotate_array.py) |
5656
| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseBits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_bits.py) |
5757
| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOf1Bit.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_1_bits.py) |
58-
| 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HouseRobber.java) |
58+
| 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HouseRobber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/house_robber.py) |
5959
| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HappyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/happy_number.py) |
6060
| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveLinkedListElements.java) |
6161
| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountPrimes.java) |

Diff for: python/house_robber.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def rob(self, nums: List[int]) -> int:
6+
a, b, max_amount = 0, nums[0], nums[0]
7+
for index in range(1, len(nums)):
8+
max_amount = max(a + nums[index], b)
9+
a, b = b, max_amount
10+
return max_amount

0 commit comments

Comments
 (0)