Given a digit string,return all possible letter combinations that the number Could represent.
A mapPing of digit to letters (just like on the telephone buttons) is given below.
input:Digit string “23”
Output: [“ad”,“ae”,“af”,“bd”,“be”,“bf”,“cd”,“ce”,“cf”].
var digitMap = []string{"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}func letterCombinations(digits string) []string { results := []string{} if len(digits) < 1 { return []string{} } letters := digitMap[int(digits[0] - '0')] if len(digits) == 1 { for _,v := range letters { results = append(results,string(v)) } } else { for _,v := range letters { for _,vs := range letterCombinations(string(digits[1:])) { results = append(results,string(v)+string(vs)) } } } return results}总结
以上是内存溢出为你收集整理的17. Letter Combinations of a Phone Number全部内容,希望文章能够帮你解决17. Letter Combinations of a Phone Number所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)