Skip to content

Instantly share code, notes, and snippets.

@nma
Created January 6, 2021 04:42
Show Gist options
  • Save nma/35bbc3cdece428c4ff29089a10fbf8bf to your computer and use it in GitHub Desktop.
Save nma/35bbc3cdece428c4ff29089a10fbf8bf to your computer and use it in GitHub Desktop.
def rob_houses_dp_no_arr(house: List[int]) -> int:
if len(house) == 0: return 0
if len(house) == 1: return house[0]
max_so_far = house[0]
max_2_houses_ago = 0
for i in len(1, len(house)):
new_max = max(max_so_far, house[i] + max_2_houses_ago)
max_2_houses_ago = max_so_far
max_so_far = new_max
return max_so_far
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment