版权声明:@author:geek_aaron https://blog.csdn.net/weixin_39433783/article/details/82984533
参考代码
class Solution:
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
if prices == None or len(prices) < 2:
return 0
profit = 0
start_vaule=0
for p in range(len(prices)-1):
if prices[p] < prices[p+1]:
start_vaule = prices[p+1]
profit += prices[p+1]-prices[p]
start_vaule = p
else:
start_vaule = min(start_vaule, p)
return profit
slo = Solution()
print(slo.maxProfit([7,1,5,3,6,4]))