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. Deepin安装 ruby 包管理工具 RVM(适用于 Debian 系列)

    1. 安装 GPG keys 先安装 gpg2 工具 sudo apt install gnupg2 再安装 keys gpg2 --recv-keys 409B6B1796C275462A17031 ...

  2. java复习(1)

    这几天开学,很多知识点还很生疏,这两天先把java基础复习一下,有段时间没有写博客了,今天就先谈谈进制转换吧. 1.二进制数的原码,补码和反码 1):对于正数的原码,补码和反码均是相同的,这里不讨论了 ...

  3. vue项目报错1 Vue is a constructor and should be called with the `new` keyword && jquery.js?eedf:3850 Uncaught TypeError: this._init is not a function...

    Vue is a constructor and should be called with the `new` keyword Uncaught TypeError: this._init is n ...

  4. npm 命令行基本操作

    npm命令选项选项            说明search 在存储库中查找模块包 npm search expressinstall  使用在存储库或本地位置上的一个package.json文件来安装 ...

  5. 为什么对华为不拍Arm?

    华为可以靠着现有的 ARMv8 授权坚持很长一段时间,足以等到这波科技禁运结束. 今天,华为在美国遭遇的科技禁运上升到了全球新高度. 据 BBC 报道,由软银全资拥有的英国技术公司 Arm 向员工发出 ...

  6. AIX中逻辑卷管理

    1.逻辑卷管理 逻辑卷的大小确定: 逻辑卷大小(MB)=PP的大小(MB)*LV包含的LP的个数 LV占用的物理空间(MB)=PP的大小(MB)*LV包含的LP的个数*LV拷贝的副本数   逻辑卷控制 ...

  7. ui自动化之selenium操作(三)xpath定位

    xpath 的定位方法,非常强大.使用这种方法几乎可以定位到页面上的任意元素. 1. 什么是xpath? xpath 是XML Path的简称, 由于HTML文档本身就是一个标准的XML页面,所以我们 ...

  8. HelloWorld的解析

    public class HelloWorld { public static void main(String[] args) { System.out.println("你好,世界!&q ...

  9. u-boot log_init函数分析

    log_init, int log_init(void){    struct log_driver *drv = ll_entry_start(struct log_driver, log_driv ...

  10. VMware导入ova报错

    报错如下: 此主机支持Intel VT-x,但Intel VT-x处于禁用状态.   解决方案如下: 联想E75主机,重启按F1进入BIOS Advanced—>CPU setup—>In ...