[LeetCode] 122. Best Time to Buy and Sell Stock II (Python)
- ๋จ์ํ๊ฒ
current
์next
๋ฅผ ๋น๊ตํด์ ๊ทธ ์ฐจ์ด๋ฅผ ๊ณ์ ๋ํด์ฃผ๋ ๋ก์ง
Solution
from typing import List
class Solution:
def maxProfit(self, prices: List[int]) -> int:
answer = 0
for i in range(len(prices) - 1):
current, next = prices[i], prices[i + 1]
if current < next:
answer += next - current
return answer
Leave a comment