leetcode198 python3 60ms 打家劫舍

class Solution:
    def rob(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if not nums:
            return 0
        if len(nums) == 1:
            return nums[0]
        dp = [nums[0], max(nums[0], nums[1])]
        for i in range(2, len(nums)):
            dp.append(max(nums[i] + dp[i-2], dp[i-1]))
        return dp[-1]
        
        
posted @ 2018-08-04 11:57  一条图图犬  阅读(382)  评论(0编辑  收藏  举报