[LeetCode/Python]

김미영·2024년 3월 12일
0

LeetCode

목록 보기
2/11

📍 문제

📝 해결

시간 복잡도 : O(n)

class Solution(object):
    def maxProfit(self, prices):
        profit = 0
        buy = prices[0]
        for sell in prices[1:]:
            if sell > buy:
                profit = max(profit, sell - buy)
            else:
                buy = sell
        
        return profit

0개의 댓글