Created
January 6, 2021 04:36
-
-
Save nma/72ab222a776a268733ac76c6406b48bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rob_houses_mem(house: Tuple[int], mem: Dict[int, int]) -> int: | |
if len(house) == 0: return 0 | |
if hash(house) in mem: | |
return mem[hash(house)] | |
criminal_gains = max( | |
rob_houses(house[1:], mem), | |
house[1] + rob_houses(house[2:], mem) | |
) | |
mem[hash(house)] = criminal_gains | |
return criminal_gains |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment