17. Letter Combinations of a Phone Number 电话号码的字母组合
生活随笔
收集整理的這篇文章主要介紹了
17. Letter Combinations of a Phone Number 电话号码的字母组合
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
給定一個僅包含數字?2-9?的字符串,返回所有它能表示的字母組合。
給出數字到字母的映射如下(與電話按鍵相同)。注意 1 不對應任何字母。
示例:
輸入:"23" 輸出:["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].說明:
盡管上面的答案是按字典序排列的,但是你可以任意選擇答案輸出的順序。
全組合
這題,沒啥好說的了,Python牛逼。
Code
def letterCombinations(self, digits: str) -> List[str]:if not digits:return []a = [['a', 'b', 'c'],['d', 'e', 'f'],['g', 'h', 'i'],['j', 'k', 'l'],['m', 'n', 'o'],['p', 'q', 'r', 's'],['t', 'u', 'v'],['w', 'x', 'y', 'z']]return [''.join(item) for item in product(*(a[index - 2] for index in list(map(int, list(digits)))))]總結
以上是生活随笔為你收集整理的17. Letter Combinations of a Phone Number 电话号码的字母组合的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 蚂蚁疾奔:蚂蚁集团两地上市全速推进
- 下一篇: 盖茨发文谈如何实现零碳目标 称看好电动车