- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1700.java
31 lines (29 loc) · 1.12 KB
/
_1700.java
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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.LinkedList;
importjava.util.Queue;
publicclass_1700 {
publicstaticclassSolution1 {
publicintcountStudents(int[] students, int[] sandwiches) {
Queue<Integer> studentsQueue = newLinkedList<>();
Queue<Integer> sandwichesQueue = newLinkedList<>();
for (inti = 0; i < sandwiches.length; i++) {
studentsQueue.add(students[i]);
sandwichesQueue.add(sandwiches[i]);
}
do {
if (!studentsQueue.isEmpty()) {
if (studentsQueue.peek() == sandwichesQueue.peek()) {
studentsQueue.poll();
sandwichesQueue.poll();
} else {
if (!studentsQueue.contains(sandwichesQueue.peek())) {
break;
}
studentsQueue.add(studentsQueue.poll());
}
}
} while (!studentsQueue.isEmpty());
returnstudentsQueue.size();
}
}
}