forked from wufenggirl/LeetCode-in-Golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblems.go
71 lines (63 loc) · 1.2 KB
/
problems.go
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
package main
type problems []problem
func (ps *problems) add(p problem) {
if len(*ps) <= p.ID {
*ps = append(*ps, make([]problem, p.ID-len(*ps)+1)...)
}
(*ps)[p.ID] = p
}
func (ps problems) accepted() problems {
res := make([]problem, 0, len(ps))
for _, p := range ps {
if p.IsAccepted {
res = append(res, p)
}
}
return res
}
func (ps problems) available() problems {
res := make([]problem, 0, len(ps))
size := len(ps)
for i := size - 1; i >= 0; i-- {
p := ps[i]
if p.isAvailable() {
res = append(res, p)
}
}
return res
}
func (ps problems) favorite() problems {
res := make([]problem, 0, len(ps))
size := len(ps)
for i := 0; i < size; i++ {
p := ps[i]
if p.IsFavor {
res = append(res, p)
}
}
return res
}
func (ps problems) unavailable() problems {
res := make([]problem, 0, len(ps))
for _, p := range ps {
if p.HasNoGoOption {
res = append(res, p)
}
}
return res
}
func (ps problems) table() string {
res := "|题号|题目|通过率|难度|收藏|\n"
res += "|:-:|:-|:-: | :-: | :-: |\n"
for _, p := range ps {
res += p.tableLine()
}
return res
}
func (ps problems) list() string {
res := ""
for _, p := range ps {
res += p.listLine()
}
return res
}