-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathquestion.go
38 lines (34 loc) · 1.05 KB
/
question.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
package question
import (
"fmt"
"strconv"
"github.com/openset/leetcode/internal/base"
"github.com/openset/leetcode/internal/leetcode"
)
var CmdQuestion = &base.Command{
Run: runQuestion,
UsageLine: "question <QuestionId>",
Short: "build problem solution file",
Long: "build problem's description,solution file.",
}
func runQuestion(cmd *base.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
}
if questionId, err := strconv.Atoi(args[0]); err == nil {
problems := leetcode.ProblemsAll()
for _, problem := range problems.StatStatusPairs {
if problem.Stat.FrontendQuestionId == questionId {
fmt.Println(questionId, "\t"+problem.Stat.QuestionTitle)
titleSlug := problem.Stat.QuestionTitleSlug
question := leetcode.QuestionData(titleSlug, true).Data.Question
if question.Content == "" && problem.PaidOnly == true && problem.Stat.QuestionArticleLive {
question.Content = leetcode.GetDescription(problem.Stat.QuestionArticleSlug)
}
question.SaveContent()
question.SaveCodeSnippet()
break
}
}
}
}