-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.txt
72 lines (56 loc) · 1.48 KB
/
3.txt
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
type AnimalShelf struct {
dogs []int
cats []int
}
func Constructor() AnimalShelf {
return AnimalShelf{}
}
func (this *AnimalShelf) Enqueue(animal []int) {
switch animal[1] {
case 0:
this.cats = append(this.cats, animal[0])
case 1:
this.dogs = append(this.dogs, animal[0])
}
}
func (this *AnimalShelf) DequeueAny() []int {
if len(this.cats) == 0 && len(this.dogs) == 0 {
return []int{-1, -1}
}
if len(this.cats) != 0 && len(this.dogs) != 0 {
if this.cats[0] < this.dogs[0] {
res := this.cats[0]
this.cats = this.cats[1:]
return []int{res, 0}
} else {
res := this.dogs[0]
this.dogs = this.dogs[1:]
return []int{res, 1}
}
}
if len(this.dogs) == 0 {
res := this.cats[0]
this.cats = this.cats[1:]
return []int{res, 0}
} else {
res := this.dogs[0]
this.dogs = this.dogs[1:]
return []int{res, 1}
}
}
func (this *AnimalShelf) DequeueDog() []int {
if len(this.dogs) == 0 {
return []int{-1, -1}
}
res := this.dogs[0]
this.dogs = this.dogs[1:]
return []int{res, 1}
}
func (this *AnimalShelf) DequeueCat() []int {
if len(this.cats) == 0 {
return []int{-1, -1}
}
res := this.cats[0]
this.cats = this.cats[1:]
return []int{res, 0}
}