forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1700.java
31 lines (29 loc) · 1.1 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
package com.fishercoder.solutions;
import java.util.LinkedList;
import java.util.Queue;
public class _1700 {
public static class Solution1 {
public int countStudents(int[] students, int[] sandwiches) {
Queue<Integer> studentsQueue = new LinkedList<>();
Queue<Integer> sandwichesQueue = new LinkedList<>();
for (int i = 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());
return studentsQueue.size();
}
}
}