[알고리즘/leetcode] Best Time to Buy and Sell Stock II(python)

유현민·2022년 8월 17일
0

알고리즘

목록 보기
226/253

for 문을 이용하여 현재 값이 다음 값보다 작으면 두수의 차를 결괏값에 더해준다.

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        ans = 0
        for i in range(len(prices) - 1):
            if prices[i] < prices[i + 1]:
                ans += prices[i + 1] - prices[i]
        return ans
profile
smilegate megaport infra

0개의 댓글