没有什么思路,代码中的while循环没看懂
class Solution {
public:
vector finalPrices(vector& prices) {
vector res;
stack stk;
for(int i = prices.size() - 1;i >= 0;i--) {
int t = prices[i];
while(stk.size() && stk.top() > t) stk.pop();
if(stk.size()) res.push_back(t - stk.top());
else res.push_back(t);
while(stk.size() && stk.top() == t) stk.pop();
stk.push(t);
}
return vector(res.begin(),res.end());
}
};