class Solution {
public:
    int maxProfit(vector<int>& prices) {
        if(prices.empty()){
            return 0;
        }
        int minpri=prices[0];
        int prof=0;
        for(int i=0;i<prices.size();i++){
            if(prices[i]<minpri){
                minpri=prices[i];
                
            }
            if(prices[i]-minpri>prof){
                prof=prices[i]-minpri;
            }
        }
        return prof;
    }
};
View Code

 

posted on 2018-05-21 20:42  苛性氢  阅读(177)  评论(0编辑  收藏  举报