leetcode122. 买卖股票的最佳时机 II(java)

leetcode122. 买卖股票的最佳时机 II(java),第1张

贪心呜呜呜

感觉不难 但是想不到 

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/890189.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-14
下一篇 2022-05-14

发表评论

登录后才能评论

评论列表(0条)

保存