Published:
Updated:

  • λ‹¨μˆœν•˜κ²Œ 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


ReferencePermalink

Leave a comment