Number of Students Unable to Eat Lunch
给两个数组, 一个数组是学生, 一个数组是三明治, 问轮转学生数组后, 有多少学生没有三明治吃
这个是个模拟题, 模拟一下即可.
class Solution {
public int countStudents(int[] st, int[] sa) {
Queue<Integer> q = new LinkedList<>();
for(int s : st){
q.add(s);
}
int j = 0;
int count = 0;
while(!q.isEmpty()){
if(count > st.length){
return q.size();
}
int cur = q.poll();
if(cur == sa[j]){
j++;
count = 0;
}
else{
q.add(cur);
count++;
}
}
return 0;
}
}