求问大佬
def letterCombinations(digits: str) -> list:if not digits:
return list()
phoneMap = {
"2": "ab",
"3": "de",
"4": "ghi",
"5": "jkl",
"6": "mno",
"7": "pqrs",
"8": "tuv",
"9": "wxyz",
}
def backtrack(index: int):
if index == len(digits):
combinations.append("".join(combination))
else:
digit = digits
for letter in phoneMap:
combination.append(letter)
print(combination)
backtrack(index + 1)
#print(combination)
combination.pop()
#print(combination)
#print(index)
combination = list()
combinations = list()
backtrack(0)
return combinations
print(letterCombinations("23"))
为啥上述代码输出的结果是['a']
['a', 'd']
['a', 'e']
['b']
['b', 'd']
['b', 'e']
['ad', 'ae', 'bd', 'be']
pop不是会把首个元素a去掉吗?
pop默认移除最后一个元素 这种问题先在网上查一下吧
list.pop()详解->https://www.runoob.com/python3/python3-att-list-pop.html
页:
[1]