반응형
leetcode.com/problems/best-time-to-buy-and-sell-stock/
class Solution:
def maxProfit(self, prices: List[int]) -> int:
max_profit = 0
sum = 0
for i in range(1, len(prices)):
sum = max(sum+prices[i]-prices[i-1], 0)
max_profit = max(sum, max_profit)
return max_profit
댓글