mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
Update ctl
This commit is contained in:
@ -51,22 +51,38 @@ func loadFile(path string) ([]int, []string, int) {
|
||||
return solutionIds, soNames, len(files)
|
||||
}
|
||||
|
||||
// GetAllFile define
|
||||
func GetAllFile(pathname string, fileList *[]string) ([]string, error) {
|
||||
rd, err := ioutil.ReadDir(pathname)
|
||||
for _, fi := range rd {
|
||||
if fi.IsDir() {
|
||||
//fmt.Printf("[%s]\n", pathname+"\\"+fi.Name())
|
||||
GetAllFile(pathname+fi.Name()+"/", fileList)
|
||||
} else {
|
||||
//fmt.Println(fi.Name())
|
||||
*fileList = append(*fileList, fi.Name())
|
||||
}
|
||||
}
|
||||
return *fileList, err
|
||||
}
|
||||
|
||||
// LoadChapterFourDir define
|
||||
func LoadChapterFourDir() []string {
|
||||
files, err := ioutil.ReadDir("../website/content/ChapterFour/")
|
||||
func LoadChapterFourDir() ([]string, []int) {
|
||||
files, err := GetAllFile("../website/content/ChapterFour/", &[]string{})
|
||||
// files, err := ioutil.ReadDir("../website/content/ChapterFour/")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
solutions, solutionIds, solutionsMap := []string{}, []int{}, map[int]string{}
|
||||
for _, f := range files {
|
||||
if f.Name()[4] == '.' {
|
||||
tmp, err := strconv.Atoi(f.Name()[:4])
|
||||
if f[4] == '.' {
|
||||
tmp, err := strconv.Atoi(f[:4])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
solutionIds = append(solutionIds, tmp)
|
||||
// len(f.Name())-3 = 文件名去掉 .md 后缀
|
||||
solutionsMap[tmp] = f.Name()[:len(f.Name())-3]
|
||||
solutionsMap[tmp] = f[:len(f)-3]
|
||||
}
|
||||
}
|
||||
sort.Ints(solutionIds)
|
||||
@ -76,7 +92,7 @@ func LoadChapterFourDir() []string {
|
||||
solutions = append(solutions, name)
|
||||
}
|
||||
}
|
||||
return solutions
|
||||
return solutions, solutionIds
|
||||
}
|
||||
|
||||
// WriteFile define
|
||||
@ -166,3 +182,11 @@ func BinarySearch(nums []int, target int) int {
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// GetChpaterFourFileNum define
|
||||
func GetChpaterFourFileNum(num int) string {
|
||||
if num < 100 {
|
||||
return fmt.Sprintf("%04d~%04d", (num/100)*100+1, (num/100)*100+99)
|
||||
}
|
||||
return fmt.Sprintf("%04d~%04d", (num/100)*100, (num/100)*100+99)
|
||||
}
|
||||
|
Reference in New Issue
Block a user