
没有什么思路,代码中的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());
}};
while(stk.size() && stk.top() > t) stk.pop();
如果栈中有值,并且栈顶值大于t,弹出栈顶元素