Skip to content

Commit f384674

Browse files
committed
leter combinations of a phone number
1 parent d43d7f7 commit f384674

File tree

1 file changed

+22
-2
lines changed
  • problems/0017.letter-combinations-of-a-phone-number

1 file changed

+22
-2
lines changed
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
package closest
22

3-
func letterCombinations(digits string) []string {
43

5-
return nil
4+
var jp = []string{"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}
5+
func letterCombinations(digits string) []string {
6+
ld := len(digits)
7+
// 初始化
8+
r := []string{}
9+
if ld == 0 {
10+
return r
11+
}
12+
r=[]string{""}
13+
for i := 0; i < ld; i++ {
14+
var tmp []string
15+
// 获取jp对应的下标
16+
index := digits[i] - '0'
17+
for _, k := range r {
18+
for _, j := range jp[index] {
19+
tmp = append(tmp, k+string(j))
20+
}
21+
}
22+
// 重新给r赋值
23+
r = tmp
24+
}
25+
return r
626
}

0 commit comments

Comments
 (0)