Number of Students Unable to Eat Lunch
给两个数组, 一个数组是学生, 一个数组是三明治, 问轮转学生数组后, 有多少学生没有三明治吃
这个是个模拟题, 模拟一下即可.
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 |
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; } } |