17. Letter Combinations of a Phone Number

17. Letter Combinations of a Phone Number,第1张

概述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

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所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1278423.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存