题解 | #买卖股票的最好时机(一)#
买卖股票的最好时机(一)
https://www.nowcoder.com/practice/64b4262d4e6d4f6181cd45446a5821ec
class Solution { public: /** * * @param prices int整型vector * @return int整型 */ int maxProfit(vector<int>& prices) { int t=0; for(int i=1;i<prices.size();i++){ if(prices[i]>prices[i-1]){ t=t>prices[i]-prices[i-1]?t:prices[i]-prices[i-1]; prices[i]=prices[i-1]; } } return t; } };