当天卖了之后,还是可以买的,所以问题简化为:只要今天比昨天大,就卖出!!!
class Solution:
def maxProfit(self, prices):
profit = 0
for i in range(len(prices)-1):
if prices[i+1]>prices[i]:
res = prices[i+1]-prices[i]
profit = profit + res
return profit
s = Solution();
print(s.maxProfit([7,1,5,3,6,4]))