LeetCode:买卖股票的最佳时机 II

C++示例程序:

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

猜你喜欢

转载自www.cnblogs.com/yiluyisha/p/9278501.html