leetcode-122-best time to buy and sell stock II

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int max=0;
        int len = prices.size();
        for(int i=1;i<len;i++){
            if(prices[i]>prices[i-1]){
                max += prices[i] - prices[i-1];
            }
        }
        return max;
    }
};

猜你喜欢

转载自blog.csdn.net/vigorqq/article/details/80977980