MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / letterCombinations

Method letterCombinations

String/LetterCombinationsOfAPhoneNumber.py:36–63  ·  view source on GitHub ↗

:type digits: str :rtype: List[str]

(self, digits)

Source from the content-addressed store, hash-verified

34"""
35class Solution(object):
36 def letterCombinations(self, digits):
37 """
38 :type digits: str
39 :rtype: List[str]
40 """
41 maps = {
42 '2': 'abc',
43 '3': 'def',
44 '4': 'ghi',
45 '5': 'jkl',
46 '6': 'mno',
47 '7': 'pqrs',
48 '8': 'tuv',
49 '9': 'wxyz'
50 }
51
52 result = []
53
54 def reduce_abc(strs, currentStr=""):
55 if not strs:
56 return currentStr
57 else:
58 for i in maps[strs[0]]:
59 x = reduce_abc(strs[1:], currentStr=currentStr+i)
60 if x:
61 result.append(x)
62 reduce_abc(digits)
63 return result

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected