1 Star 3 Fork 5

刘炜/python LeetCode

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
1496按摩师.py 579 Bytes
Copy Edit Raw Blame History
刘炜 authored 2020-03-24 23:39 . 动态规划
class Solution:
def massage(nums):
if len(nums) == 0:
return 0
elif len(nums) == 1:
return nums[0]
elif len(nums) == 2:
return max(nums[0], nums[1])
else:
beforeyes = nums[0]
yesday = nums[1]
now = 0
for i in range(2,len(nums)-1):
now = max(nums[i] + beforeyes, yesday)
beforeyes = yesday
yesday = now
return max(nums[len(nums)-1] + beforeyes, yesday)
s = Solution
n = [2,1,1,2]
print(s.massage(n))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/new_way/python-LeetCode.git
git@gitee.com:new_way/python-LeetCode.git
new_way
python-LeetCode
python LeetCode
master

Search