leetcode121 C++ 12ms 买股票的最佳时机 只能买卖一次
class Solution {
public:
int maxProfit(vector
if( prices.empty() || prices.size() < 1){
return 0;
}
int mi = prices[0];
int res = 0;
for(int i=1; i < prices.size(); i++){
res = res > prices[i] - mi ? res:prices[i] - mi;
mi = mi < prices[i] ? mi: prices[i];
}
return res;
}
};