class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param students int整型vector
* @param sandwiches int整型vector
* @return int整型
*/
int countStudents(vector<int>& students, vector<int>& sandwiches) {
// write code here
deque<int> deq;
stack<int> st;
for (int num : students)
deq.push_back(num);
for(int i=sandwiches.size()-1;i>=0;i--)
st.push(sandwiches[i]);
while (!st.empty()) {
if (st.top() == deq.front()) {
st.pop();
deq.pop_front();
} else {
int n = deq.size() - 1,k=0;
for (int i = 0; i < n; i++) {
deq.push_back(deq.front());
deq.pop_front();
if (st.top() == deq.front()) {
st.pop();
deq.pop_front();
k=1;
break;
}
}
if(k==0)
return n+1;
}
}
return 0;
}
};