Best Time to Buy and Sell Stock II
Example
Solution
class Solution:
"""
@param prices: Given an integer array
@return: Maximum profit
"""
#贪心算法,得出不计次数的买卖的最大利润。
def maxProfit(self, prices):
total = 0
for i in range(1, len(prices)):
if prices[i] > prices[i-1]:
total += prices[i] - prices[i-1]
return totalLast updated