zoukankan      html  css  js  c++  java
  • leetcode17 Letter Combinations of a Phone Number

     1 """
     2 Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
     3 A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
     4 Example:
     5 Input: "23"
     6 Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
     7 """
     8 """
     9 本题三次循环,看不懂debug一遍就好了
    10 """
    11 class Solution1:
    12     def letterCombinations(self, digits):
    13         phone = {'2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl', '6': 'mno', '7': 'pqrs', '8': 'tuv', '9': 'wxyz'}
    14         digits = 23
    15         if digits == '':
    16             return []
    17         result = ['']
    18         for digit in digits:
    19             lst = phone[digit]
    20             newresult = []
    21             for x in result:   #!!!保存现有的排列组合
    22                 for y in lst:  #
    23                     newresult.append(x + y)
    24             result = newresult
    25         return result
    26 
    27 # phone = {'2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl', '6': 'mno', '7': 'pqrs', '8': 'tuv', '9': 'wxyz'}
    28 # digits = '23'
    29 # result = ['']
    30 # for digit in digits:
    31 #     lst = phone[digit]
    32 #     newresult = []
    33 #     for x in result:   #!!!保存现有的排列组合
    34 #         for y in lst:  #
    35 #             newresult.append(x + y)
    36 #     result = newresult
    37 #
    38 # print(result)
  • 相关阅读:
    go相关
    mac下使用vscode技巧
    mac下secureCRT的使用技巧
    python subprocess实时输出
    python中多级目录导入模块问题
    python的print与sys.stdout
    python中类相关笔记
    python中sys.stdout.flush()的作用
    nginx+uwsgi配置
    虚拟机的 基本配置
  • 原文地址:https://www.cnblogs.com/yawenw/p/12268845.html
Copyright © 2011-2022 走看看