Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb7a397f

Browse files
committed
update cmd library
1 parentb8df881 commitb7a397f

File tree

12 files changed

+175
-134
lines changed

12 files changed

+175
-134
lines changed

‎cmd/leetcode/makedir.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"os"
88
)
99

10-
constSOLUTIONS_APTH="solutions/"
10+
constSOLUTIONS_PATH="src/"
1111
constSOURCE_SOLUTION_FILE_PATH="cmd/template/solution/solution.go"
1212
constSOURCE_SOLUTION_TEST_FILE_PATH="cmd/template/solution/solution_test.go"
1313
constSOURCE_SOLUTION_README_FILE_PATH="cmd/template/solution/README.md"
@@ -28,17 +28,18 @@ func MakeDir(problems []Problem) {
2828
continue
2929
}
3030

31-
ifis_DirExists,_:=PathExists(SOLUTIONS_APTH+problems[i].PathName);is_DirExists {
32-
log.Println("目录已经存在:",SOLUTIONS_APTH+problems[i].PathName)
31+
ifis_DirExists,_:=PathExists(SOLUTIONS_PATH+problems[i].PathName);is_DirExists {
32+
log.Println("目录已经存在:",SOLUTIONS_PATH+problems[i].PathName)
3333
}else {
34-
err:=os.Mkdir(SOLUTIONS_APTH+problems[i].PathName,os.ModePerm)
34+
err:=os.Mkdir(SOLUTIONS_PATH+problems[i].PathName,os.ModePerm)
3535
iferr!=nil {
3636
log.Printf("目录创建失败:%s",err.Error())
3737
}else {
3838
//复制文件
3939
log.Println("开始复制文件:")
40-
copy(SOURCE_SOLUTION_FILE_PATH,SOLUTIONS_APTH+problems[i].PathName+"/solution.go")
41-
copy(SOURCE_SOLUTION_TEST_FILE_PATH,SOLUTIONS_APTH+problems[i].PathName+"/solution_test.go")
40+
copy(SOURCE_SOLUTION_FILE_PATH,SOLUTIONS_PATH+problems[i].PathName+"/Solution.go")
41+
copy(SOURCE_SOLUTION_TEST_FILE_PATH,SOLUTIONS_PATH+problems[i].PathName+"/Solution_test.go")
42+
GenerateReadme(problems[i])
4243
}
4344
}
4445

‎cmd/leetcode/makedir_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package leetcode
22

33
import (
4+
"fmt"
45
"testing"
56
)
67

78
funcTestMakeDir(t*testing.T) {
8-
//problems := GetProblemsInstance()
9+
problems:=GetSotedproblemsInstance()
10+
fmt.Println(len(problems))
11+
12+
for_,v:=rangeproblems {
13+
ifv.PaidOnly {
14+
fmt.Println(v)
15+
}
16+
fmt.Println(v)
17+
}
918

10-
//for _, v := range problems {
11-
//if v.PaidOnly {
12-
//
13-
//fmt.Println(v)
14-
//}
15-
//}
1619
//MakeDir(problems)
1720
}

‎cmd/leetcode/problem-readme.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
package leetcode
22

33
import (
4+
"bytes"
45
"fmt"
6+
"html/template"
57
"io/ioutil"
68
"log"
9+
"os"
710
)
811

912
funcGetReadmeTemplateBuffer()string {
10-
data,err:=ioutil.ReadFile(SOURCE_SOLUTION_README_FILE_PATH)
13+
data,err:=ioutil.ReadFile(SOURCE_SOLUTION_SUMMARY_FILE_PATH)
1114
iferr!=nil {
1215
log.Panicln("读取 README模板失败",err.Error())
1316
}
1417
fmt.Println(string(data))
1518
returnstring(data)
1619
}
20+
21+
funcGenerateReadme(problemProblem) {
22+
log.Println("开始生成 README")
23+
file,err:=os.OpenFile(SOURCE_SOLUTION_README_FILE_PATH,os.O_RDONLY,0600)
24+
deferfile.Close()
25+
iferr!=nil {
26+
log.Panicf("README 模板读取失败1:%s",err.Error())
27+
}
28+
29+
buffer,err:=ioutil.ReadAll(file)
30+
iferr!=nil {
31+
log.Panicf("README 模板读取失败2:%s",err.Error())
32+
}
33+
34+
vartmpRes bytes.Buffer
35+
36+
tmpl,err:=template.New("README: ").Parse(string(buffer))
37+
err=tmpl.Execute(&tmpRes,problem)
38+
write(SOLUTIONS_PATH+problem.PathName+"/README.md",string(tmpRes.Bytes()))
39+
}

‎cmd/leetcode/problem.go

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package leetcode
22

33
import (
44
"encoding/json"
5+
"errors"
6+
"fmt"
57
"io/ioutil"
68
"log"
79
"net/http"
@@ -32,6 +34,7 @@ type Problem struct {
3234
Frequencyint`json:"frequency"`
3335
Progressint`json:"progress"`
3436
PathNamestring`json:"path_name"`
37+
DirPathstring`json:"dir_path"`
3538
}
3639
typeStatstruct {
3740
QuestionIDint`json:"question_id"`
@@ -80,7 +83,7 @@ func GetProblemsInstance() []Problem {
8083
returnleetcode.StatStatusPairs
8184
}
8285

83-
funcGetSotedproblemsInstance() []Problem {
86+
funcGetSortedProblemsInstance() []Problem {
8487
problems:=GetProblemsInstance()
8588
//插入排序
8689
problems=sortProblems(problems)
@@ -102,7 +105,7 @@ func sortProblems(problems []Problem) []Problem {
102105
returnproblems
103106
}
104107

105-
funcGetProblemsJosn()string {
108+
funcGetProblemsJson()string {
106109
problems:=GetProblemsInstance()
107110
problem_string,err:=json.MarshalIndent(problems," "," ")
108111
iferr!=nil {
@@ -149,11 +152,23 @@ func formatId(id int) string {
149152
funcformatName(namestring)string {
150153
str:=""
151154
fori,v:=rangename {
155+
ifv==' '&&name[i-1]!='-' {
156+
str=str+"-"
157+
continue
158+
}
152159
ifv==' ' {
160+
continue
161+
}
162+
ifv=='`' {
153163
str=str+"-"
154164
continue
155165
}
156-
ifv=='(' {
166+
ifv=='%' {
167+
str=str+"p"
168+
continue
169+
}
170+
171+
ifv=='('&&name[i-1]!='-' {
157172
str=str+"-"
158173
continue
159174
}
@@ -164,6 +179,13 @@ func formatName(name string) string {
164179
ifv==',' {
165180
continue
166181
}
182+
// ' 过滤
183+
ifv==39 {
184+
continue
185+
}
186+
ifv=='?' {
187+
continue
188+
}
167189
ifi>0&&name[i-1]=='-' {
168190
str=str+string(v)
169191
continue
@@ -175,3 +197,18 @@ func formatName(name string) string {
175197
}
176198
returnstr
177199
}
200+
201+
funcUrlPath(pathstring)error {
202+
resp,err:=http.Get(path)
203+
iferr!=nil {
204+
fmt.Println(err)
205+
returnerrors.New(path+" "+err.Error())
206+
}
207+
208+
ifresp.StatusCode!=200 {
209+
fmt.Println(resp.StatusCode)
210+
returnerrors.New(string(resp.StatusCode))
211+
}
212+
213+
returnnil
214+
}

‎cmd/leetcode/problem_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package leetcode
2+
3+
import (
4+
"testing"
5+
)
6+
7+
funcTestUrlPath(t*testing.T) {
8+
t.Run("1",func(t*testing.T) {
9+
err:=UrlPath("https://www.baidu.com")
10+
iferr!=nil {
11+
t.Fatal(err.Error())
12+
}
13+
})
14+
}

‎cmd/main.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
package main
22

3-
funcmain() {
4-
//problems :=leetcode.GetSotedproblemsInstance()
5-
//problems := leetcode.GetProblemsJosn()
3+
import (
4+
"github.com/kylesliu/awesome-golang-leetcode/cmd/leetcode"
5+
)
66

7+
funcmain() {
8+
problems:=leetcode.GetSortedProblemsInstance()
9+
//problems := leetcode.GetProblemsJson()
10+
//fmt.Println(problems)
711
//for _, v := range problems {
8-
//fmt.Println(v.Stat.QuestionID)
9-
//fmt.Println(v.Stat.QuestionTitle)
10-
//fmt.Println(v.PathName)
12+
//fmt.Println(v.Stat.QuestionID, v.Stat.QuestionTitle, v.PathName,v.Stat.QuestionTitleSlup)
13+
//err := leetcode.UrlPath("https://leetcode.com/problems/" + v.Stat.QuestionTitleSlup )
14+
//if err != nil {
15+
//fmt.Println(v.Stat.QuestionID, v.Stat.QuestionTitle, v.PathName,v.Stat.QuestionTitleSlup)
16+
//fmt.Println(err.Error())
17+
//}
1118
//}
1219

1320
//生成Problem 目录
21+
1422
//leetcode.MakeDir(problems)
1523

1624
//leetcode.GetReadmeTemplateBuffer()
1725

1826
//GitBook
19-
//leetcode.MakeGitbookSummary(problems)
27+
leetcode.MakeGitbookSummary(problems)
2028

2129
}

‎cmd/template/gitbook/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
*[Contributor](CONTRIBUTOR.md)
55
* Soutions(1-976)
66
{{ range . }}*[{{.PathName}}](./src/{{.PathName}}/README.md)
7-
{{ end }}
7+
{{ end }}

‎cmd/template/solution/README.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
1-
#Summary
2-
3-
*[Summary](SUMMARY-LIST.md)
4-
* Soutions(1-976)
5-
{{ range . }}*[{{.PathName}}](./src/{{.PathName}}/README.md)
6-
{{ end }}
1+
#[{{.Stat.FrontendQuestionID}}.{{ .Stat.QuestionTitle}}][title]
2+
3+
>[!WARNING|style:flat]
4+
>This question is temporarily unanswered if you have good ideas. Welcome to[Create Pull Request PR](https://github.com/kylesliu/awesome-golang-leetcode)
5+
6+
##Description
7+
8+
**Example 1:**
9+
10+
```
11+
Input: a = "11", b = "1"
12+
Output: "100"
13+
```
14+
15+
##题意
16+
>...
17+
18+
##题解
19+
20+
###思路1
21+
>...
22+
{{ .Stat.QuestionTitle}}
23+
```go
24+
```
25+
26+
27+
##结语
28+
29+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:[awesome-golang-leetcode][me]
30+
31+
[title]:https://leetcode.com/problems/{{ .Stat.QuestionTitleSlup }}/
32+
[me]:https://github.com/kylesliu/awesome-golang-leetcode

‎cmd/template/solution/solution.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎cmd/template/solution/solution_test.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎cmd/tree/tree.go

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp