https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
因为可以进行无限次交易,并且在下一次buy之前必须已经sell。所以只需要把所有price曲线价格上涨的部分加起来就行。
参考
http://www.cnblogs.com/zuoyuan/p/3765980.html
class Solution(object):
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
maxprofit = 0
for i in range(1, len(prices)):
if prices[i] >= prices[i-1]:
maxprofit += prices[i] - prices[i-1]
return maxprofit