Python 알고리즘 인터뷰 - 문제 78. 주식을 사고팔기 가장 좋은 시점 II

2024. 3. 6. 00:02코딩 테스트/파이썬 알고리즘 인터뷰

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/

 

Best Time to Buy and Sell Stock II - LeetCode

Can you solve this real interview question? Best Time to Buy and Sell Stock II - You are given an integer array prices where prices[i] is the price of a given stock on the ith day. On each day, you may decide to buy and/or sell the stock. You can only hold

leetcode.com

 

전체 코드

class Solution(object):
    def maxProfit(self, prices: list):
        result = sum([max(prices[i + 1] - prices[i], 0) for i in range(len(prices) - 1)])
        return result