class Solution { public: /** * @param prices: Given an integer array * @return: Maximum profit */ int maxProfit(vector<int> &prices) { // write your code here int ret = 0; if(prices.size()<2) return ret; int lowest = prices[0]; for(int i=1;i<prices.size();i++) { int cur = prices[i]; ret = max(ret,cur-lowest); lowest = min(lowest,cur); } return ret; } };