-
Notifications
You must be signed in to change notification settings - Fork 41
/
solution.ts
58 lines (53 loc) · 1.46 KB
/
solution.ts
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
55
56
57
58
class AnimalShelf {
private queenCat:number[][];
private queenDog:number[][];
constructor () {
this.queenCat = [];
this.queenDog = [];
}
enqueue (animal: number[]): void {
if (animal[1] === 0) {
this.queenCat.push(animal);
} else {
this.queenDog.push(animal);
}
}
dequeueAny (): number[] {
if (this.queenCat.length === 0 && this.queenDog.length === 0) {
return [-1, -1, ];
}
if (this.queenCat.length && this.queenDog.length) {
if (this.queenCat[0][0] < this.queenDog[0][0]) {
return this.queenCat.shift();
} else {
return this.queenDog.shift();
}
} else if (this.queenCat.length) {
return this.queenCat.shift();
} else {
return this.queenDog.shift();
}
}
dequeueDog (): number[] {
if (this.queenDog.length === 0) {
return [-1, -1, ];
} else {
return this.queenDog.shift();
}
}
dequeueCat (): number[] {
if (this.queenCat.length === 0) {
return [-1, -1, ];
} else {
return this.queenCat.shift();
}
}
}
/**
* Your AnimalShelf object will be instantiated and called as such:
* var obj = new AnimalShelf()
* obj.enqueue(animal)
* var param_2 = obj.dequeueAny()
* var param_3 = obj.dequeueDog()
* var param_4 = obj.dequeueCat()
*/