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. docker之本地连接

    docker安装成功,之后我们需要连接进入docker中,这里罗列连接方式 1. Windows7 一般的虚拟ip地址: 192.168.99.100 查看ip地址: 1)  C:\Users\thi ...

  2. 完整阿里云Redis开发规范

    完整阿里云Redis开发规范 原文地址 本文主要介绍在使用阿里云Redis的开发规范,从下面几个方面进行说明. 键值设计 命令使用 客户端使用 相关工具 删除bigkey 通过本文的介绍可以减少使用R ...

  3. 白话算法:时间复杂度和大O表示法

    转自:https://www.jianshu.com/p/59d09b9cee58 每一个优秀的开发者脑中都有时间概念.他们想给用户更多的时间让用户做他们想做的事情.他们通过最小化时间复杂度来实现这一 ...

  4. zabbix监控之同时向多人邮件报警

    安装环境:  zabbix-server zabbix邮件报警配置步骤说明: 安装发送邮件的工具sendEmail 准备一个发送邮件的脚本 修改zabbix配置文件中指定的脚本路径 关联脚本名称 用户 ...

  5. for迭代

    for迭代 Python中最简单的循环机制是 while,打开交互式解释器,执行1到的5的循环 >>> count=1 >>> while count<=5: ...

  6. Ubuntu无法安装nginx

    1.问题Reading package lists... DoneBuilding dependency tree       Reading state information... DoneSom ...

  7. CSS3 transform 属性 旋转 div 元素

    div { transform:rotate(7deg); -ms-transform:rotate(7deg); /* IE 9 */ -moz-transform:rotate(7deg); /* ...

  8. 用PS修改PNG格式图标的颜色

    需求:将黑色的PNG格式图标,更改为其它颜色 原始图标:   原始图标 - 黑色   方法1: 图层样式 -> 颜色叠加     选择颜色叠加     选择想要的颜色   方法2: 更换颜色 一 ...

  9. exe 错误

    1,NTVDM 是从 WINDOWS NT 架构开始引入的一个子系统进程,目的是虚拟一个DOS环境来运行以前的DOS 16bit 程序.2,只有当启动16位DOS程序时,才会启用 NTVDM 这个进程 ...

  10. pandas的corsstab

      pandas.crosstab(index, columns, values=None, rownames=None, colnames=None, aggfunc=None, margins=F ...