剑指OFFER----面试题63. 股票的最大利润
链接:https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/、
代码
class Solution {
public:
int maxProfit(vector<int>& prices) {
int res = 0;
if (prices.empty()) return 0;
for (int i = 1, minv = prices[0]; i < prices.size(); ++i) {
res = max(res, prices[i] - minv);
minv = min(minv, prices[i]);
}
return res;
}
};