Skip to content

Instantly share code, notes, and snippets.

@nma
Created January 6, 2021 04:36
Show Gist options
  • Save nma/72ab222a776a268733ac76c6406b48bf to your computer and use it in GitHub Desktop.
Save nma/72ab222a776a268733ac76c6406b48bf to your computer and use it in GitHub Desktop.
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