跳的有点远了,15、16先略过,哈哈,其实我就是看到电话号码,感觉有点顺眼,就做这道题了。
这道题还是很简单的,每次用一个中间链表记录下来,然后再做就可以了。
class Solution:def letterCombinations(self, digits: str) -> List[str]:y = []y1 = []a = {}a['2'] = ['a','b','c']a['3'] = ['d','e','f']a['4'] = ['g','h','i']a['5'] = ['j','k','l']a['6'] = ['m','n','o']a['7'] = ['p','q','r','s']a['8'] = ['t','u','v']a['9'] = ['w','x','y','z']p = []# 对输入的每一个字符for i in range(len(digits)):# 对字符key对应的每一个字符for j in range(len(a[digits[i]])):if i == 0:y.append(a[digits[i]][j])else:for k in range(len(y)):y1.append(y[k]+a[digits[i]][j])# print('y:',y)# print('y1:',y1)if i == 0:p = yelse:p = y1# print('p:',p)y = p# print('y:',y)y1 = []# print('y1',y1)# print()return p
一遍过,哈哈