买卖股票最好时机
买卖股票的最好时机
http://www.nowcoder.com/questionTerminal/64b4262d4e6d4f6181cd45446a5821ec
记录一下最小值,O(N)扫一遍
class Solution { public: /** * * @param prices int整型vector * @return int整型 */ int maxProfit(vector<int>& prices) { int minn = 0x3f3f3f3f,ans = 0; for(auto i:prices) { ans = max(ans,i - minn); minn = min(i,minn); } return ans; } };