1 class Solution 2 { 3 public: 4 bool IsPopOrder(vector<int> pushV,vector<int> popV) { 5 if(pushV.size() != popV.size()) 6 return false; 7 stack<int> Stack; 8 int i = 0,j = 0; 9 while(i < pushV.size()) 10 { 11 Stack.push(pushV[i ++]); 12 //出栈队列中的元素和栈顶元素相等就出栈 13 while(j < popV.size() && popV[j] == Stack.top()) 14 { 15 Stack.pop(); 16 j ++; 17 } 18 } 19 return Stack.empty();//栈空则返回true 20 } 21 };
时间: 2024-12-28 16:05:46