Skip to content

Commit

Permalink
Fix addMod
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Jan 29, 2023
1 parent 9b5cc9d commit f3ebe00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ func Default() *Config {
Modifiers: []Modifier{
{Name: "removeUselessComments"},
{Name: "changeReceiverName"},
{Name: "addMod"},
{Name: "addNamedReturn"},
{Name: "addMod"},
},
},
},
Expand Down
9 changes: 7 additions & 2 deletions lang/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ func addMod(code string, q *leetcode.QuestionData) string {
var returnType string
for _, line := range lines {
if strings.HasPrefix(line, "func ") {
rightBrace := strings.LastIndex(line, ")")
returnType = strings.TrimSpace(line[rightBrace+1 : strings.LastIndex(line, "{")])
if strings.Count(line, "(") == 1 {
rightBrace := strings.LastIndex(line, ")")
returnType = strings.TrimSpace(line[rightBrace+1 : strings.LastIndex(line, "{")])
} else {
s := line[strings.LastIndex(line, "(")+1 : strings.LastIndex(line, ")")]
returnType = s[strings.LastIndex(s, " ")+1:]
}
newLines = append(newLines, line)
newLines = append(newLines, "\tconst mod int = 1e9 + 7\n")
} else if strings.HasPrefix(line, "\treturn") {
Expand Down

0 comments on commit f3ebe00

Please sign in to comment.