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

代码

/*
 * @lc app=leetcode.cn id=122 lang=cpp
 *
 * [122] 买卖股票的最佳时机 II
 */

// @lc code=start
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int ans = 0;
        for (int i = 0; i + 1 < prices.size(); ++i) {
            ans += max(0, prices[i + 1] - prices[i]);
        }
        return ans;
    }
};
// @lc code=end

posted @ 2020-07-27 10:34  景云ⁿ  阅读(48)  评论(0编辑  收藏  举报