LeetCode - 122. 买卖股票的最佳时机 II

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

class Solution {
    public int maxProfit(int[] prices) {
        
        int sum = 0;
        
        for (int i = 1;i < prices.length; ++ i) {
            if (prices[i] > prices[i - 1]) {
                sum += prices[i] - prices[i - 1];
            }
        }
        
        return sum;
    }
}


猜你喜欢

转载自blog.51cto.com/tianyiya/2174495
今日推荐