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;
    }
};
posted @ 2018-07-07 21:29  一路一沙  阅读(166)  评论(0编辑  收藏  举报