meishaoming / blog

MIT License
1 stars 2 forks source link

leetcode-面试题 17.16. 按摩师 #85

Open meishaoming opened 4 years ago

meishaoming commented 4 years ago

https://leetcode-cn.com/problems/the-masseuse-lcci/

下午做过一遍与这个相似的题, #82

一遍就写出了解法,比下午写的简法要更简洁。

class Solution:
    def massage(self, nums: List[int]) -> int:
        a, b = 0, 0
        for x in nums:
            a, b = b, max(a+x, b)
        return b
image