代码:
class Solution:
"""
@param prices: Given an integer array
@return: Maximum profit
"""
def maxProfit(self, prices):
# write your code here
#由于买卖次数无限,所以只要能获利就进行买卖,这样能保证所有利润都吃到自然利润最大。
max = 0
for i in range(1, len(prices)):
cur = prices[i] - prices[i - 1]
if cur > 0:
max += cur
return max