思路
与其说是动态规划,倒不如说是贪心。
class Solution {
public:
int maxProfit(vector<int>& prices) {
int res = 0;
int minPrice = INT_MAX;
for (int price : prices) {
minPrice = min(minPrice, price);
res = max(res, price - minPrice);
}
return res;
}
};