文章目录
题目
代码(7.16 首刷自解)
class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
stack<int> stk;
int j = 0;
for(int i = 0; i < pushed.size(); i++) {
stk.push(pushed[i]);
while(!stk.empty() && stk.top() == popped[j]) {
j++;
stk.pop();
}
}
return stk.empty();
}
};
加粗样式