파이썬 알고리즘 인터뷰 78번(리트코드 122번) Best Time to Buy and Sell Stock II
https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
class Solution:
def maxProfit(self, prices: List[int]) -> int:
profit = 0
stack = []
for price in prices:
if not stack or stack[-1] <= price:
stack.append(price)
else:
profit += stack[-1] - stack[0]
stack = [price]
profit += stack[-1] - stack[0]
return profit
class Solution:
def maxProfit(self, prices: List[int]) -> int:
profit = 0
buy = prices[0]
for sell in prices:
if sell > buy:
profit += sell - buy
buy = sell
return profit