网址:https://leetcode.com/problems/validate-stack-sequences/
参考:https://leetcode.com/problems/validate-stack-sequences/discuss/197667/Java-straight-forward-stack-solution.
模拟过程
class Solution { public: bool validateStackSequences(vector<int>& pushed, vector<int>& popped) { stack<int> temp; int i = 0; for(int num : pushed) { temp.push(num); while(!temp.empty() && temp.top() == popped[i]) { temp.pop(); i++; } } return temp.empty(); } };