class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
stack<int> tmp;
int i=0;
for(auto s:pushed){
tmp.push(s);//stack没有push_back?
while(!tmp.empty()&&popped[i]==tmp.top()){//这两个条件不能写反
tmp.pop();
i++;
}
}
return tmp.empty();
}
};
作者:Dddddebug
链接:https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/solution/fu-zhu-zhan-by-dddddebug-hayq/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。