标签:pre fit 思路 ++ 简介 auto turn lan tor
使用感觉类似动态规划的思路进行计算
class Solution {
public:
int maxProfit(vector<int>& prices) {
int inf = 1e9;
int minPrice = inf;
int maxProfit = 0;
for(auto it :prices) {
maxProfit = max(maxProfit, it - minPrice);
minPrice = min(minPrice, it);
}
return maxProfit;
}
};
class Solution {
public int maxProfit(int[] prices) {
int inf = 1000000000;
int minPrice = inf, maxProfit = 0;
for(int it : prices) {
maxProfit = Math.max(maxProfit, it - minPrice);
minPrice = Math.min(minPrice, it);
}
return maxProfit;
}
}
标签:pre fit 思路 ++ 简介 auto turn lan tor
原文地址:https://www.cnblogs.com/eat-too-much/p/14774630.html