class Solution {
public:
int maxProfit(vector<int>& prices) {
int len = prices.size();
int max = 0;
for(int i=0;i<len-1;i++){
for(int j=i+1;j<len;j++){
if(prices[j]-prices[i]>max){
max = prices[j]-prices[i];
}
}
}
return max;
}
};
还有一种方法是从尾部开始搜索,大的就标记为售出价。