class Solution { public: int maxProfit(vector<int> &prices) { if(prices.size()==0) return 0; int min=prices[0],max=0,sum=prices.size(); for(int i=0;i<sum-1;i++) { if(prices[i+1]<min) { min=prices[i+1]; } else { if(max<prices[i+1]-min) max=prices[i+1]-min; } } return max; } };