Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8d72c7f

Browse files
author
Yeqi Tao
committed
Add Soulution.go for 0017.Letter Combinations of a Phone Number
1 parent 5d498f3 commit 8d72c7f

File tree

1 file changed

+28
-0
lines changed
  • solution/0017.Letter Combinations of a Phone Number

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var table = map[string][]string {
2+
"2": {"a", "b", "c"},
3+
"3": {"d", "e", "f"},
4+
"4": {"g", "h", "i"},
5+
"5": {"j", "k", "l"},
6+
"6": {"m", "n", "o"},
7+
"7": {"p", "q", "r", "s"},
8+
"8": {"t", "u", "v"},
9+
"9": {"w", "x", "y", "z"},
10+
}
11+
12+
func letterCombinations(digits string) []string {
13+
if digits == "" {
14+
return make([]string, 0)
15+
}
16+
var result = table[string(digits[0])]
17+
for i:=1; i<len(digits); i++ {
18+
t := table[string(digits[i])]
19+
nr := make([]string, len(result) * len(t))
20+
for j:=0; j<len(result); j++ {
21+
for k:=0; k<len(t); k++ {
22+
nr[len(t)*j + k] = result[j] + t[k]
23+
}
24+
}
25+
result = nr
26+
}
27+
return result
28+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /