-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDay69.cpp
36 lines (30 loc) · 852 Bytes
/
Day69.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
int isStackPermutation(int n,vector<int> &a,vector<int> &b){
queue<int>q1;
queue<int>q2;
stack<int>stk;
for(auto i:a)
q1.push(i);
for(auto i:b)
q2.push(i);
while(!q1.empty()){
int t=q1.front();
q1.pop();
if(t==q2.front()){
q2.pop();
while(!stk.empty()){
if(stk.top()==q2.front()){
stk.pop();
q2.pop();
}
else
break;
}
}
else
stk.push(t);
}
if(q1.empty()&&stk.empty())
return 1;
else
return 0;
}