vector<int> finalPrices(vector<int> &prices) {
deque<int> d;
vector<int> v(prices.size());
for (int i = 0; i < prices.size(); i++) {
while (!d.empty() && prices[d.back()] >= prices[i])
v[d.back()] = prices[d.back()] - prices[i], d.pop_back();
d.emplace_back(i);
}
while (!d.empty())
v[d.back()] = prices[d.back()], d.pop_back();
return v;
}
1475. 商品折扣后的最终价格
最新推荐文章于 2023-08-14 20:48:22 发布