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

相关文章:

  • 2021-08-02
  • 2021-07-27
  • 2021-10-12
  • 2021-04-13
  • 2021-07-11
  • 2021-05-17
猜你喜欢
  • 2021-04-14
  • 2021-10-28
相关资源
相似解决方案