【DP】【贪心】122.买卖股票的最佳时机II

题目

法1:贪心,最佳解法

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

股票问题总结

六种股票问题总结https://blog.csdn.net/weixin_47692079/article/details/117202705

你可能感兴趣的:(DP,贪心)