Leetcode-198 打家劫舍

Leetcode-198 打家劫舍_第1张图片

class Solution:
    def rob(self, nums: List[int]) -> int:
        cur, pre = 0, 0
        for num in nums:
            cur, pre = max(pre + num, cur), cur
        return cur

你可能感兴趣的:(leetcode,深度优先,算法)