class Solution {
public:
    /**
     * 
     * @param prices int整型vector 
     * @return int整型
     */
    int maxProfit(vector<int>& prices) {
        // write code here
        // 一段段的升序数组,要下跌的时候就卖
        int ans = 0;
        int temp = prices[0];
        for(int i=1; i<prices.size(); ++i)
        {
            if(prices[i-1]>prices[i])
            {
                ans += (prices[i-1]-temp);
                temp = prices[i];
            }
            if(i==(prices.size()-1))
            {
                ans += (prices[i]-temp);
            }
        }

        return ans;
    }
};