
class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
stack<int> st;
for(int i=0,j=0;i<pushed.size();i++){
st.push(pushed[i]);
while(!st.empty()&&st.top()==popped[j]){
st.pop();
j++;
}
}
return st.empty();
}
};
原创
leetcode946. 验证栈序列
本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。