标签:turn code ems pre 试题 empty int max 面试
链接: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;
}
};
标签:turn code ems pre 试题 empty int max 面试
原文地址:https://www.cnblogs.com/clown9804/p/12491996.html