1-2数组-买卖股票的最佳时机II

JAVA

class Solution {
    public int maxProfit(int[] prices) {
        int profit = 0;
        for(int i =0; iprices[i]) profit += prices[i+1]-prices[i];
        }
        return profit;
        
    }
}

python

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        profit = 0
        for i in range(len(prices)-1):
            if prices[i+1]>prices[i]:
                profit += prices[i+1]-prices[i]
        return profit

你可能感兴趣的:(1-2数组-买卖股票的最佳时机II)