[LeetCode] 122. Best Time to Buy and Sell Stock II (Python)
- λ¨μνκ²
current
μnext
λ₯Ό λΉκ΅ν΄μ κ·Έ μ°¨μ΄λ₯Ό κ³μ λν΄μ£Όλ λ‘μ§
SolutionPermalink
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