forked from wufenggirl/LeetCode-in-Golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleetcode-new.go
68 lines (53 loc) · 1.11 KB
/
leetcode-new.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
package main
import (
"encoding/json"
"log"
"time"
"github.com/aQuaYi/GoKit"
)
const (
unavailableFile = "unavailable.json"
)
func getLeetCode() *leetcode {
probs, record := parseAlgs(getAlgorithms())
lc := &leetcode{
Username: getConfig().Username,
Record: record,
Problems: *probs,
Ranking: getRanking(),
Updated: time.Now(),
}
return lc
}
func parseAlgs(alg *algorithms) (*problems, record) {
hasNoGoOption := readUnavailable()
probs := &problems{}
r := record{}
for _, ps := range alg.Problems {
p := newProblem(ps)
if hasNoGoOption[p.ID] {
p.HasNoGoOption = true
}
probs.add(p)
r.update(p)
}
return probs, r
}
func readUnavailable() map[int]bool {
type unavailable struct {
List []int
}
if !GoKit.Exist(unavailableFile) {
log.Panicf("%s 不存在,没有不能解答的题目", unavailableFile)
}
raw := read(unavailableFile)
u := unavailable{}
if err := json.Unmarshal(raw, &u); err != nil {
log.Panicf("获取 %s 失败:%s", unavailableFile, err)
}
res := make(map[int]bool, len(u.List))
for i := range u.List {
res[u.List[i]] = true
}
return res
}