不限次数,求股票交易的最大利润及交易次数

一次交易包含买入卖出2次操做python   思路:code 方法一:只要prices[i+1]>prices[i]就累加diff=prices[i+1]>prices[i],此法能够获得最大利润,没法获得最少交易数it 法二:求出全部波峰波谷,累加波峰波谷的差值,能够获得最大利润和最少交易次数class   def max_profit(prices): n=len(prices)
相关文章
相关标签/搜索