[LeetCode] 122. Best Time to Buy and Sell Stock II
medium是你的谎言.
class Solution:
def maxProfit(self, prices: List[int]) -> int:
#1
if len(prices) == 1:
return 0
#else
max_profit = 0
min_price = prices[0]
for i, element in enumerate(prices):
#find a min_price
if element <= min_price:
min_price = element
else:
#sell immediately
max_profit += element - min_price
min_price = element
return max_profit