198. House Robber

202401312242
tags:

from functools import lru_cache
	class Solution:
		def rob(self, nums: List[int]) -> int:
			@lru_cache(maxsize=None)
			def solve(i):
				if i == 0:
					return nums[0]
				if i == 1:
					return max(nums[0], nums[1])
				option1 = solve(i - 2) + nums[i]
				option2 = solve(i - 1)
				return max(option1, option2)
			return solve(len(nums) - 1)

Reference

https://leetcode.com/problems/house-robber/