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; } };