- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1670.java
54 lines (45 loc) · 1.38 KB
/
_1670.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
53
54
packagecom.fishercoder.solutions.secondthousand;
importjava.util.ArrayList;
importjava.util.List;
publicclass_1670 {
publicstaticclassSolution1 {
/*
* This is a brute force approach.
* TODO: use two Deques to implement a solution.
*/
publicstaticclassFrontMiddleBackQueue {
List<Integer> list;
publicFrontMiddleBackQueue() {
list = newArrayList<>();
}
publicvoidpushFront(intval) {
list.add(0, val);
}
publicvoidpushMiddle(intval) {
list.add(list.size() / 2, val);
}
publicvoidpushBack(intval) {
list.add(val);
}
publicintpopFront() {
if (list.size() > 0) {
returnlist.remove(0);
}
return -1;
}
publicintpopMiddle() {
if (list.size() > 0) {
returnlist.remove(
list.size() % 2 == 0 ? list.size() / 2 - 1 : list.size() / 2);
}
return -1;
}
publicintpopBack() {
if (list.size() > 0) {
returnlist.remove(list.size() - 1);
}
return -1;
}
}
}
}