Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Dec 13, 2023
1 parent 724df9a commit 52cd41f
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"fmt"
)

func letterCombinations(digits string) []string {
result := []string{}
if len(digits) == 0 {
return result
}

phoneMap := []string{"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}
result = append(result, "")
for _, v := range digits {
s := phoneMap[v-'2']
temp := []string{}
for _, i := range result {
for _, j := range s {
temp = append(temp, i+string(j))
}
}
result = temp
}

return result
}

func main() {
digits := "25"
fmt.Println(letterCombinations(digits))
}

0 comments on commit 52cd41f

Please sign in to comment.