mycode  68.26%

class Solution(object):
def letterCombinations(self, digits):
"""
:type digits: str
:rtype: List[str]
"""
if digits == "":
return []
dict = {'':['a','b','c'],
'':['d','e','f'],
'':['g','h','i'],
'':['j','k','l'],
'':['m','n','o'],
'':['p','q','r','s'],
'':['t','u','v'],
'':['w','x','y','z']
}
def dfs(index,temp):
if index==self.len:
self.res.append(temp)
return
num = digits[index]
s = dict[num]
for i in s:
dfs(index+1,temp+i)
self.res = []
self.len = len(digits)
dfs(0,"")
return self.res

参考:

def letterCombinations(digits):
def dfs(num, string):
if num == length:
res.append(string)
return
for letter in dict[digits[num]]:
dfs(num+1, string+letter) dict = {'':['a','b','c'],
'':['d','e','f'],
'':['g','h','i'],
'':['j','k','l'],
'':['m','n','o'],
'':['p','q','r','s'],
'':['t','u','v'],
'':['w','x','y','z']
}
res = []
length = len(digits)
dfs(0, '')
return res

leetcode-mid-backtracking-17. Letter Combinations of a Phone Number的更多相关文章

  1. leetcode个人题解——#17 Letter Combinations of a Phone Number

    思路:用深搜遍历九宫格字符串,一开始做的时候发生了引用指向空地址的问题,后来发现是vector不能直接=赋值. class Solution { public: int len; ]={"a ...

  2. [LeetCode][Python]17: Letter Combinations of a Phone Number

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...

  3. Leetcode 17. Letter Combinations of a Phone Number(水)

    17. Letter Combinations of a Phone Number Medium Given a string containing digits from 2-9 inclusive ...

  4. 刷题17. Letter Combinations of a Phone Number

    一.题目说明 题目17. Letter Combinations of a Phone Number,题目给了下面一个图,输入一个字符串包括2-9,输出所有可能的字符组合. 如输入23所有可能的输出: ...

  5. 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  6. [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合

    Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...

  7. [leetcode 17]Letter Combinations of a Phone Number

    1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...

  8. 【一天一道LeetCode】#17. Letter Combinations of a Phone Number

    一天一道LeetCode (一)题目 Given a digit string, return all possible letter combinations that the number cou ...

  9. [leetcode]17. Letter Combinations of a Phone Number手机键盘的字母组合

    Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...

  10. 17. Letter Combinations of a Phone Number (backtracking)

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

随机推荐

  1. 11.jQuery之淡入淡出效果

    知识点:fadeIn   fadeOut  fadeToggle  fadeTo <style> div { width: 150px; height: 300px; background ...

  2. doT学习(二)之用法集合

    Advanced templating: illustrates defines and includes. Include external snippet defined in a variabl ...

  3. npm学习(二)之如何防止权限错误

    如何防止权限错误 如果您在尝试全局安装包时看到EACCES错误,请阅读本章.如果更改安装npm的目录,通常可以避免此错误.要做到这一点,要么使用版本管理器重新安装npm(推荐)或手动更改npm的默认目 ...

  4. 34、Scrapy 知识总结

      Scrapy 知识总结   1.安装   pip install wheel pip install https://download.lfd.uci.edu/pythonlibs/q5gtlas ...

  5. iptables-save - 保存 IP Tables

    总览 SYNOPSIS iptables-save [-c] [-t table] 描述 DESCRIPTION iptables-save 用来将 IP Table 转储为可以简单解析的格式,输出到 ...

  6. 随机发送n位数字+字母的验证码

    ''' 随机发送n位数字+字母的验证码 ''' import random def get_verified(length): code = '' for i in range(length): nu ...

  7. NETCONF

    NETCONF协议(Network Configration Protocol) NETCONF是一个基于XML的交换机配置接口,用于替代CLI.SNMP等配置交换机. 本质上来说,NETCONF就是 ...

  8. Linux shell 下简单的进度条实现

    Linux shell 下简单的进度条实现 [root@db145 ~]# cat print_process.sh function Proceess(){ spa='' i= ] do print ...

  9. 用class语法派生Enum并增加描述值的类属性来定义一个新枚举

    import enum class BugStatus(enum.Enum):        new = 7    incomplete = 6    invalid = 5    wont_fix ...

  10. tf.split( )和tf.unstack( )

    import tensorflow as tf A = [[1, 2, 3], [4, 5, 6]] a0 = tf.split(A, num_or_size_splits=3, axis=1)#不改 ...