class Solution {
public:
    /**
     * 
     * @param prices int整型vector 
     * @return int整型
     */
    int maxProfit(vector<int>& prices) {
        int len = prices.size();
        vector<int> dp(len, 0);//i买入获取最大利润
        int maxProfit = 0;
        // dp[j] = max(nums[j]-nums[i], dp[j]);
        for(int i=0; i<len-1; i++) { // i买入
            for(int j=i+1; j<len; j++) {// j卖出
                dp[i] = max(dp[i], prices[j]-prices[i]);
                // cout<< i<< " "<< j<< ":"<< prices[j]-prices[i]<<endl;
                maxProfit = max(dp[i], maxProfit);
            }
        }
        return maxProfit;
    }
};