Skip to content

Commit e2a88a6

Browse files
author
Openset
committed
Update: order by id desc
1 parent 6d05a1c commit e2a88a6

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

internal/leetcode/tag.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"path"
7+
"strconv"
78
"strings"
89
)
910

@@ -92,11 +93,23 @@ func (tag tagType) SaveContents() {
9293
buf.WriteString("| # | 题名 | 标签 | 难度 |\n")
9394
buf.WriteString("| :-: | - | - | :-: |\n")
9495
format := "| %s | [%s](https://github.com/openset/leetcode/tree/master/problems/%s) | %s | %s |\n"
96+
maxId := 0
97+
rows := make(map[int]string)
9598
for _, question := range questions {
99+
id, err := strconv.Atoi(question.QuestionFrontendId)
100+
checkErr(err)
96101
if question.TranslatedTitle == "" {
97102
question.TranslatedTitle = question.Title
98103
}
99-
buf.WriteString(fmt.Sprintf(format, question.QuestionFrontendId, question.TranslatedTitle, question.TitleSlug, question.TagsStr(), question.Difficulty))
104+
rows[id] = fmt.Sprintf(format, question.QuestionFrontendId, question.TranslatedTitle, question.TitleSlug, question.TagsStr(), question.Difficulty)
105+
if id > maxId {
106+
maxId = id
107+
}
108+
}
109+
for i := maxId; i > 0; i-- {
110+
if row, ok := rows[i]; ok {
111+
buf.WriteString(row)
112+
}
100113
}
101114
filename := path.Join("tag", tag.Slug, "README.md")
102115
filePutContents(filename, buf.Bytes())

0 commit comments

Comments
 (0)