# 【LeetCode】17. 电话号码的字母组合

### 2 答案

``````class Solution:
def letterCombinations(self, digits: str) -> List[str]:
hashmap = {2:'abc', 3:'def', 4:'ghi', 5:'jkl', 6:'mno', 7:'pqrs', 8:'tuv', 9:'wxyz'}
if digits = "" return []
list1 = []
res = []
for s in digits:
list1.append(hashmap[int(s)])
for i in range(len(list1)):
for j in range(i+1, len(list1)):

ii = len(list1[i])
jj = len(list1[j])
while ii != -1:

res.append(list1[i][ii]+list1[j][jj])
ii -= 1
``````

``````class Solution:
def letterCombinations(self, digits: str) -> List[str]:
if not digits: return []

phone = {'2':['a','b','c'],
'3':['d','e','f'],
'4':['g','h','i'],
'5':['j','k','l'],
'6':['m','n','o'],
'7':['p','q','r','s'],
'8':['t','u','v'],
'9':['w','x','y','z']}

def backtrack(conbination,nextdigit):
if len(nextdigit) == 0:
res.append(conbination)
else:
for letter in phone[nextdigit[0]]:
backtrack(conbination + letter,nextdigit[1:])

res = []
backtrack('',digits)
return res
``````

``````class Solution:
def letterCombinations(self, digits: str) -> List[str]:
if not digits: return []
phone = ['abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']
queue = ['']
for digit in digits:
for _ in range(len(queue)):
tmp = queue.pop(0)
for letter in phone[ord(digit)-50]:
queue.append(tmp + letter)
return queue
``````

THE END