Best Time to Buy and Sell Stock
class Solution { public: int maxProfit(vector<int> &prices) { int size = prices.size(); if( size==0 || size==1) return 0; int minPrice = prices[0]; int curMax = 0; for(int i = 1;i < size; ++i) { if(prices[i] > minPrice) curMax = max( curMax , prices[i] - minPrice); else if( prices[i] < minPrice) minPrice = prices[i]; } return curMax; } };