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

Commitc14d8d6

Browse files
committed
add some solutions
1 parentcbd926d commitc14d8d6

File tree

1,419 files changed

+2170
-14938
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,419 files changed

+2170
-14938
lines changed

‎cmd/config.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
package main
22

3-
typeGitHubstruct {
4-
}
3+
typeGitHubstruct{}

‎cmd/contribution.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ type Contributor struct {
1818
ContributionType []string`json:"contribution_type"`
1919
}
2020

21-
constGITHUB_CONTRIBUTOR_API_URL="https://api.github.com/repos/kylesliu/awesome-golang-algorithm/contributors"
22-
constGITHUB_CONTRIBUTOR_TMPL_PATH="./tpl/.all-contributorsrc"
21+
const (
22+
GITHUB_CONTRIBUTOR_API_URL="https://api.github.com/repos/kylesliu/awesome-golang-algorithm/contributors"
23+
GITHUB_CONTRIBUTOR_TMPL_PATH="./tpl/.all-contributorsrc"
24+
)
2325

2426
funcgetContributorBufer() []byte {
25-
2627
contributor_buffer:=Request("GET",GITHUB_CONTRIBUTOR_API_URL,nil)
2728

2829
returncontributor_buffer
@@ -57,14 +58,15 @@ func GetContributorInstance() []Contributor {
5758
}
5859
returncontributors
5960
}
61+
6062
funcgetContributorTemplate()string {
6163
buffer:=ReadFile(GITHUB_CONTRIBUTOR_TMPL_PATH)
6264
returnstring(buffer)
6365
}
6466

6567
funcGenerateContributorTemplete() {
6668
tpl_str:=getContributorTemplate()
67-
//fmt.Println(tpl_str)
69+
//fmt.Println(tpl_str)
6870
contributors:=GetContributorInstance()
6971

7072
fmt.Println(contributors)

‎cmd/github/contribution.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ type Contributor struct {
1212
Urlstring`json:"url"`
1313
}
1414

15-
constGITHUB_CONTRIBUTOR_API_URL="https://api.github.com/repos/kylesliu/awesome-golang-algorithm/contributors"
16-
constGITHUB_CONTRIBUTOR_TMPL_PATH="cmd/template/contributors/.all-contributorsrc"
15+
const (
16+
GITHUB_CONTRIBUTOR_API_URL="https://api.github.com/repos/kylesliu/awesome-golang-algorithm/contributors"
17+
GITHUB_CONTRIBUTOR_TMPL_PATH="cmd/template/contributors/.all-contributorsrc"
18+
)
1719

1820
funcgetContributorBufer() []byte {
1921
request,err:=http.Get(GITHUB_CONTRIBUTOR_API_URL)
20-
2122
iferr!=nil {
2223
log.Panicln("Lettcode Problem 接口获取失败:",err)
2324
}

‎cmd/leetcode.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Problem struct {
2424
Progressint`json:"progress"`
2525
PathNamestring`json:"path_name"`
2626
}
27+
2728
typeStatstruct {
2829
QuestionIDint`json:"question_id"`
2930
QuestionArticleLivebool`json:"question__article__live"`
@@ -42,5 +43,4 @@ type Difficulty struct {
4243
}
4344

4445
funcGetAllleetcodeInstance() {
45-
4646
}

‎cmd/leetcode/makedir.go‎

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

10-
constSOLUTIONS_PATH="leetcode/"
11-
constSOURCE_SOLUTION_FILE_PATH="cmd/template/solution/solution.go"
12-
constSOURCE_SOLUTION_TEST_FILE_PATH="cmd/template/solution/solution_test.go"
13-
constSOURCE_SOLUTION_README_FILE_PATH="cmd/template/solution/README.md"
10+
const (
11+
SOLUTIONS_PATH="leetcode/"
12+
SOURCE_SOLUTION_FILE_PATH="cmd/template/solution/solution.go"
13+
SOURCE_SOLUTION_TEST_FILE_PATH="cmd/template/solution/solution_test.go"
14+
SOURCE_SOLUTION_README_FILE_PATH="cmd/template/solution/README.md"
15+
)
1416

1517
//生成木目录Dir
1618
funcMakeDir(problems []Problem) {
1719
fori:=0;i<len(problems);i++ {
18-
//fmt.Println(problems[i].PathName)
20+
//fmt.Println(problems[i].PathName)
1921
log.Printf("~~ 开始生成第 %d 题的文件夹 ~~",problems[i].Stat.FrontendQuestionID)
2022

2123
//检查数据
@@ -46,29 +48,29 @@ func MakeDir(problems []Problem) {
4648
}
4749
}
4850

49-
//拷贝文件 要拷贝的文件路径 拷贝到哪里
51+
//拷贝文件 要拷贝的文件路径 拷贝到哪里
5052
funccopyFile(source,deststring)bool {
5153
ifsource==""||dest=="" {
5254
log.Println("source or dest is null")
5355
returnfalse
5456
}
55-
//打开文件资源
57+
//打开文件资源
5658
source_open,err:=os.Open(source)
57-
//养成好习惯。操作文件时候记得添加 defer 关闭文件资源代码
59+
//养成好习惯。操作文件时候记得添加 defer 关闭文件资源代码
5860
iferr!=nil {
5961
log.Println(err.Error())
6062
returnfalse
6163
}
6264
defersource_open.Close()
63-
//只写模式打开文件 如果文件不存在进行创建 并赋予 644的权限。详情查看linux 权限解释
65+
//只写模式打开文件 如果文件不存在进行创建 并赋予 644的权限。详情查看linux 权限解释
6466
dest_open,err:=os.OpenFile(dest,os.O_CREATE|os.O_WRONLY,644)
6567
iferr!=nil {
6668
log.Println(err.Error())
6769
returnfalse
6870
}
69-
//养成好习惯。操作文件时候记得添加 defer 关闭文件资源代码
71+
//养成好习惯。操作文件时候记得添加 defer 关闭文件资源代码
7072
deferdest_open.Close()
71-
//进行数据拷贝
73+
//进行数据拷贝
7274
_,copy_err:=io.Copy(dest_open,source_open)
7375
ifcopy_err!=nil {
7476
log.Println(copy_err.Error())

‎cmd/leetcode/makedir_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ func TestMakeDir(t *testing.T) {
1616
fmt.Println(v)
1717
}
1818

19-
//MakeDir(problems)
19+
//MakeDir(problems)
2020
}

‎cmd/leetcode/problem-readme.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func GetReadmeTemplateBuffer() string {
2020

2121
funcGenerateReadme(problemProblem) {
2222
log.Println("开始生成 README")
23-
file,err:=os.OpenFile(SOURCE_SOLUTION_README_FILE_PATH,os.O_RDONLY,0600)
23+
file,err:=os.OpenFile(SOURCE_SOLUTION_README_FILE_PATH,os.O_RDONLY,0o600)
2424
deferfile.Close()
2525
iferr!=nil {
2626
log.Panicf("README 模板读取失败1:%s",err.Error())

‎cmd/leetcode/problem.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type Problem struct {
3636
PathNamestring`json:"path_name"`
3737
DirPathstring`json:"dir_path"`
3838
}
39+
3940
typeStatstruct {
4041
QuestionIDint`json:"question_id"`
4142
QuestionArticleLivebool`json:"question__article__live"`
@@ -59,15 +60,14 @@ func GetAllProblemsPath() []string {
5960
res:= []string{}
6061
time.Sleep(time.Second)
6162

62-
fori,_:=rangeproblems {
63+
fori:=rangeproblems {
6364
res=append(res,problems[i].PathName)
64-
//fmt.Println(problems[i].Stat.QuestionTitle)
65+
//fmt.Println(problems[i].Stat.QuestionTitle)
6566
}
6667
returnres
6768
}
6869

6970
funcGetProblemsInstance() []Problem {
70-
7171
leetcode:=new(LeetCode)
7272
Problemsbuffer:=getProblemsBuffer()
7373

@@ -118,7 +118,6 @@ func GetProblemsJson() string {
118118
//获取题目Buffer
119119
funcgetProblemsBuffer() []byte {
120120
request,err:=http.Get("https://leetcode.com/api/problems/Algorithms/")
121-
122121
iferr!=nil {
123122
log.Panicln("Lettcode Problem 接口获取失败:",err)
124123
}

‎cmd/leetcode/summary.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type TodoPageData struct {
2525
funcMakeGitbookSummary(problems []Problem) {
2626
problems=CheckProblemExists(problems)
2727

28-
file,err:=os.OpenFile(SOURCE_SOLUTION_SUMMARY_FILE_PATH,os.O_RDONLY,0600)
28+
file,err:=os.OpenFile(SOURCE_SOLUTION_SUMMARY_FILE_PATH,os.O_RDONLY,0o600)
2929
deferfile.Close()
3030
iferr!=nil {
3131
log.Panicf("README 模板读取失败1:%s",err.Error())
@@ -42,6 +42,7 @@ func MakeGitbookSummary(problems []Problem) {
4242
err=tmpl.Execute(&tmpRes,problems)
4343
write("SUMMARY.md",string(tmpRes.Bytes()))
4444
}
45+
4546
funcCheckProblemExists(problems []Problem) []Problem {
4647
tmp:= []Problem{}
4748

@@ -57,7 +58,7 @@ func CheckProblemExists(problems []Problem) []Problem {
5758
}
5859

5960
funcwrite(path,contentstring) {
60-
err:=ioutil.WriteFile(path, []byte(content),0755)
61+
err:=ioutil.WriteFile(path, []byte(content),0o755)
6162
iferr!=nil {
6263
log.Fatal(err)
6364
}
@@ -79,5 +80,4 @@ func readTMPL(path string) string {
7980
}
8081

8182
funcgetSUMMARYBuffer(filepathstring) {
82-
8383
}

‎cmd/main.go‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package main
22

33
import (
4-
"fmt"
5-
64
"awesome-golang-algorithm/cmd/leetcode"
5+
"fmt"
76
)
87

98
funcmain() {
@@ -25,15 +24,14 @@ func main() {
2524

2625
//生成Problem 目录
2726

28-
//leetcode.MakeDir(problems)
27+
//leetcode.MakeDir(problems)
2928

30-
//leetcode.GetReadmeTemplateBuffer()
29+
//leetcode.GetReadmeTemplateBuffer()
3130

3231
//GitBook
33-
//leetcode.MakeGitbookSummary(problems)
32+
//leetcode.MakeGitbookSummary(problems)
3433

3534
//sitemap
3635
// s := sitemap.New(problems)
3736
// fmt.Println(s)
38-
3937
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp