标签:elf git nbsp tco sel div append 思路 def
回溯法
思路:
通过回溯的思维,递归调用枚举出所有可能。
class Solution: def letterCombinations(self, digits): 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(combination, next_digits): if len(next_digits) == 0: output.append(combination) else: for letter in phone[next_digits[0]]: backtrack(combination + letter, next_digits[1:]) output = [] if digits: backtrack("", digits) return output
标签:elf git nbsp tco sel div append 思路 def
原文地址:https://www.cnblogs.com/nilhxzcode/p/12801313.html