mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-08-06 13:51:26 +08:00
规范格式
This commit is contained in:
@ -0,0 +1,39 @@
|
||||
package leetcode
|
||||
|
||||
var (
|
||||
letterMap = []string{
|
||||
" ", //0
|
||||
"", //1
|
||||
"abc", //2
|
||||
"def", //3
|
||||
"ghi", //4
|
||||
"jkl", //5
|
||||
"mno", //6
|
||||
"pqrs", //7
|
||||
"tuv", //8
|
||||
"wxyz", //9
|
||||
}
|
||||
res = []string{}
|
||||
)
|
||||
|
||||
func letterCombinations(digits string) []string {
|
||||
if digits == "" {
|
||||
return []string{}
|
||||
}
|
||||
res = []string{}
|
||||
findCombination(&digits, 0, "")
|
||||
return res
|
||||
}
|
||||
|
||||
func findCombination(digits *string, index int, s string) {
|
||||
if index == len(*digits) {
|
||||
res = append(res, s)
|
||||
return
|
||||
}
|
||||
num := (*digits)[index]
|
||||
letter := letterMap[num-'0']
|
||||
for i := 0; i < len(letter); i++ {
|
||||
findCombination(digits, index+1, s+string(letter[i]))
|
||||
}
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user