验证栈序列
https://leetcode.cn/problems/validate-stack-sequences/
/*
* @lc app=leetcode.cn id=946 lang=cpp
*
* [946] 验证栈序列
*/
// @lc code=start
class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
int size = pushed.size();
stack<int> st;
int j = 0;
for (int i = 0; i < size; i++) {
st.push(pushed[i]);
while (!st.empty() && st.top() == popped[j]) {
st.pop();
j++;
}
}
return st.empty();
}
};
// @lc code=end