DP is the array containing the max money you can rob up to that point.
Solve using DP and then try to optimize for memory
SOLUTION
class Solution(object):
def rob(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
dp = []
a = 0
b = 0
for cost in nums:
dp.append(max(b+cost,a))
temp = max(b+cost,a)
b = a
a = temp
return dp[-1]
solution
class Solution(object):
def rob(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
a = 0
b = 0
for cost in nums:
temp = max(b+cost,a
b = a
a = temp
return a