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
动态规划_leetcode121(好难,双状态)
猜你喜欢
转载自www.cnblogs.com/lux-ace/p/10546508.html
今日推荐
周排行