动态规划_leetcode121(好难,双状态)

class Solution(object):
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""

if not prices:
return 0


buy = -prices[0]

sell = 0


for i in range(1,len(prices)):
buy = max(buy ,-prices[i])
sell = max (sell,prices[i] + buy)

return sell
posted @ 2019-03-17 12:50  AceKo  阅读(330)  评论(0编辑  收藏  举报