122. Best Time to Buy and Sell Stock II

ๆˆ‘ๆจ่ฟ™ไธช้ข˜๏ผŒ่ฟ™็”š่‡ณไธๆ˜ฏ็œŸ็š„dpๅง๏ผŒไธ็Ÿฅ้“ๅœจ่€ƒไป€ไนˆ

class Solution {
    public int maxProfit(int[] prices) {
        int maxP = 0;
        for (int i = 1; i < prices.length; i++) {
            maxP += Math.max(0, prices[i] - prices[i-1]);
        }
        return maxP;
    }
}

Last updated