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

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


链接点我

题目描述

在这里插入图片描述

思路

在这里插入图片描述

    public int maxProfit(int[] prices) {
        if(prices == null || prices.length == 0){
            return 0;
        }
        int maxProfit = 0;
        for(int i = 0; i < prices.length-1; i++){
            if(prices[i+1] > prices[i]){
                maxProfit += prices[i+1]-prices[i];
            }
        }
        return maxProfit;
    }
发布了55 篇原创文章 · 获赞 1 · 访问量 867

猜你喜欢

转载自blog.csdn.net/weixin_42469108/article/details/105088709