-
Notifications
You must be signed in to change notification settings - Fork 14
/
PassportCheckpoint.java
52 lines (44 loc) · 1.49 KB
/
PassportCheckpoint.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package by.andd3dfx.common;
import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Queue;
/**
* <pre>
* Implement a class Entry that will be used as a part of a larger simulation of a passport checkpoint.
*
* The class Entry needs to contain the following methods:
* • void enter(String passportNumber) - puts the specified passport number at the end of the line.
* • String exit() - removes the passport from the queue and returns the passport. If no passports are in the queue,
* null should be returned.
*
* For example, the following code snippet should write "AB54321", "UK32032":
* Entry entry = new Entry();
* entry.enter("AB54321");
* entry.enter("UK32032");
*
* System.out.println(entry.Exit());
* System.out.println(entry.Exit());
* </pre>
*
* @see <a href="https://youtu.be/DAjin0U7NHA">Video solution</a>
*/
public class PassportCheckpoint {
public static class Solution1 {
private Queue<String> queue = new ArrayDeque<>();
public void enter(String passportNumber) {
queue.add(passportNumber);
}
public String exit() {
return queue.poll();
}
}
public static class Solution2 {
private LinkedList<String> queue = new LinkedList<>();
public void enter(String passportNumber) {
queue.add(passportNumber);
}
public String exit() {
return queue.poll();
}
}
}