티스토리 뷰

728x90
class Solution {
    public int maxProfit(int[] prices) {
        int buy = Integer.MIN_VALUE;
        int cooldown = 0;

        int sell = 0;
        for (int p : prices) {
            buy = Math.max(buy, cooldown - p);
            cooldown = Math.max(cooldown, sell);

            sell = Math.max(sell, buy + p);
        }

        return sell;
    }
}

https://gonewbie.github.io/2020/02/26/daily-algorithm-best-time-to-buy-and-sell-stock/

 

daily-algorithm-best-time-to-buy-and-sell-stock · gonewbie's Studio

동적 프로그래밍 알고리즘 해결에 있어서 문제를 해결하는 가장 기본적인 방법은 분할 정복(Divide & Conquer)이다. 즉, 커다란 문제를 여러 개의 작은 문제로 나누어 처리하는 것이다. 프로그래밍

gonewbie.github.io

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

 

Best Time to Buy and Sell Stock with Cooldown - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

728x90
댓글