Published:
Updated:

  • ๋‹จ์ˆœํ•˜๊ฒŒ 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


Reference

Leave a comment