class Solution(object):
def rob(self, nums): """ :type nums: List[int] :rtype: int """ n=len(nums) if n==0: return 0 if n==1: return nums[0] i=2 maxinums=[nums[0],max(nums[0],nums[1])] while i<n: maxinums.append(max(maxinums[i-1],maxinums[i-2]+nums[i])) i+=1 return maxinums[n-1]sol=Solution()print sol.rob(nums=[4,5,6,1])