This repository was archived by the owner on Sep 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathproblem.go
91 lines (75 loc) · 2.02 KB
/
problem.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"fmt"
"strings"
)
type problem struct {
ID int
Title string
TitleSlug string
PassRate string
Difficulty string
IsAccepted, IsPaid, IsFavor, IsNew bool
HasNoGoOption bool // 不能够使用 Go 语言解答
}
func newProblem(ps problemStatus) problem {
level := []string{"", "Easy", "Medium", "Hard"}
p := problem{
ID: ps.State.ID,
Title: ps.State.Title,
TitleSlug: ps.State.TitleSlug,
// p.Submitted + 1 是因为刚刚添加的新题的 submitted 为 0
PassRate: fmt.Sprintf("%d%%", ps.ACs*100/(ps.Submitted+1)),
Difficulty: level[ps.Difficulty.Level],
IsAccepted: ps.Status == "ac",
IsPaid: ps.IsPaid,
IsFavor: ps.IsFavor,
IsNew: ps.State.IsNew,
}
return p
}
func (p problem) isAvailable() bool {
if p.ID == 0 || p.IsPaid || p.HasNoGoOption {
return false
}
return true
}
func (p problem) Dir() string {
path := "Algorithms"
return fmt.Sprintf("./%s/%04d.%s", path, p.ID, p.TitleSlug)
}
func (p problem) link() string {
return fmt.Sprintf("https://leetcode.com/problems/%s/", p.TitleSlug)
}
func (p problem) tableLine() string {
// 题号
res := fmt.Sprintf("|[%04d](%s)|", p.ID, p.link())
// 标题
t := ""
if p.IsAccepted {
t = fmt.Sprintf(`[%s](%s)`, strings.TrimSpace(p.Title), p.Dir())
} else {
t = fmt.Sprintf(` * %s`, p.Title)
}
if p.IsNew {
t += " :new: "
}
res += t + "|"
// 通过率
res += fmt.Sprintf("%s|", p.PassRate)
// 难度
res += fmt.Sprintf("%s|", p.Difficulty)
// 收藏
f := ""
if p.IsFavor {
f = "[❤](https://leetcode.com/list/oussv5j)"
}
res += fmt.Sprintf("%s|\n", f)
return res
}
func (p problem) listLine() string {
return fmt.Sprintf("- [%d.%s](%s)\n", p.ID, p.Title, p.link())
}
func (p problem) didaTask(prefix string) string {
return fmt.Sprintf("#%s - %04d - #%s - %s - %s - %s", prefix, p.ID, p.Difficulty, p.PassRate, p.Title, p.link())
}