@@ -18,17 +18,37 @@ type Mdrow struct {
18
18
19
19
// GenerateMdRows define
20
20
func GenerateMdRows (solutionIds []int , mdrows []Mdrow ) {
21
- //fmt.Printf("solutionIds = %v\n\n", solutionIds)
21
+ mdMap := map [int ]Mdrow {}
22
+ for _ , row := range mdrows {
23
+ mdMap [int (row .FrontendQuestionID )] = row
24
+ }
22
25
for i := 0 ; i < len (solutionIds ); i ++ {
23
- //fmt.Printf("solutionIds[i] = %v id = %v - %v\n", solutionIds[i], mdrows[solutionIds[i]].FrontendQuestionID, mdrows[solutionIds[i]].QuestionTitle)
24
- id := mdrows [solutionIds [i ]- 1 ].FrontendQuestionID
25
- if solutionIds [i ] == int (id ) {
26
- //fmt.Printf("id = %v i = %v solutionIds = %v\n", id, i, solutionIds[i])
27
- mdrows [id - 1 ].SolutionPath = fmt .Sprintf ("[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/%v)" , fmt .Sprintf ("%04d.%v" , id , strings .Replace (strings .TrimSpace (mdrows [id - 1 ].QuestionTitle ), " " , "-" , - 1 )))
26
+ if row , ok := mdMap [solutionIds [i ]]; ok {
27
+ mdMap [solutionIds [i ]] = Mdrow {
28
+ FrontendQuestionID : row .FrontendQuestionID ,
29
+ QuestionTitle : row .QuestionTitle ,
30
+ QuestionTitleSlug : row .QuestionTitleSlug ,
31
+ SolutionPath : fmt .Sprintf ("[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/%v)" , fmt .Sprintf ("%04d.%v" , solutionIds [i ], strings .Replace (strings .TrimSpace (row .QuestionTitle ), " " , "-" , - 1 ))),
32
+ Acceptance : row .Acceptance ,
33
+ Difficulty : row .Difficulty ,
34
+ Frequency : row .Frequency ,
35
+ }
28
36
} else {
29
- fmt .Printf ("序号出错了 len(solutionIds) = %v len(mdrows) = %v len(solutionIds) = %v solutionIds[i] = %v id = %v - %v\n " , len (solutionIds ), len (mdrows ), len (solutionIds ), solutionIds [i ], id , mdrows [solutionIds [i ]- 1 ].QuestionTitle )
37
+ fmt .Printf ("序号不存在 len(solutionIds) = %v len(mdrows) = %v len(solutionIds) = %v solutionIds[i] = %v QuestionTitle = %v\n " , len (solutionIds ), len (mdrows ), len (solutionIds ), solutionIds [i ], mdrows [solutionIds [i ]- 1 ].QuestionTitle )
38
+ }
39
+ }
40
+ for i := range mdrows {
41
+ mdrows [i ] = Mdrow {
42
+ FrontendQuestionID : mdrows [i ].FrontendQuestionID ,
43
+ QuestionTitle : mdrows [i ].QuestionTitle ,
44
+ QuestionTitleSlug : mdrows [i ].QuestionTitleSlug ,
45
+ SolutionPath : mdMap [int (mdrows [i ].FrontendQuestionID )].SolutionPath ,
46
+ Acceptance : mdrows [i ].Acceptance ,
47
+ Difficulty : mdrows [i ].Difficulty ,
48
+ Frequency : mdrows [i ].Frequency ,
30
49
}
31
50
}
51
+ // fmt.Printf("mdrows = %v\n\n", mdrows)
32
52
}
33
53
34
54
// | 0001 | Two Sum | [Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0001.Two-Sum)| 45.6% | Easy | |
0 commit comments