class Solution {
  public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param prices int整型vector
     * @return int整型
     */
    int max_profitv2(vector<int>& prices) {
        // write code here
        int maxx = 0;
        int n = prices.size();
        for (int i = 1; i < n; ++i) {
            if (prices[i] > prices[i - 1])
                maxx += prices[i] - prices[i - 1];
        }
        return maxx;
    }
};

一、题目考察的知识点

贪心

二、题目解答方法的文字分析

首先第一天不能交易

从第二天开始,如果当天价格高于前一天,那么就可以获得利润,在遍历的过程中把获得的利润加起来就是答案

三、本题解析所用的编程语言

c++