1. class Solution {
    2. public:
    3. int maxProfit(vector<int>& prices) {
    4. if(prices.size() <=0 ){
    5. return 0;
    6. }
    7. int min_price = prices[0];
    8. int profit = 0;
    9. for(int i = 1; i<prices.size(); i++){
    10. min_price = min(min_price, prices[i]);
    11. profit = max(profit, prices[i] - min_price);
    12. }
    13. return profit;
    14. }
    15. };