Given a string contains only numeric characters 2-9, it can return all letter combinations indicated.
Given digital map to letters as follows (the same telephone key). Note 1 does not correspond to any alphabet.
Links: https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/
Nothing to say, it is time to test the other hand cheap play a few numbers, the computer can not move the card
class Solution:
def letterCombinations(self, digits: str):
if len(digits)==0:
return []
maps = {
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']
}
lists = maps[int(digits[0])]
for each in digits[1:]:
new_lists = []
for s in lists:
for c in maps[int(each)]:
new_lists.append(s+c)
lists= new_lists
return lists
#s = Solution()