mycode  68.26%

  1. class Solution(object):
  2. def letterCombinations(self, digits):
  3. """
  4. :type digits: str
  5. :rtype: List[str]
  6. """
  7. if digits == "":
  8. return []
  9. dict = {'':['a','b','c'],
  10. '':['d','e','f'],
  11. '':['g','h','i'],
  12. '':['j','k','l'],
  13. '':['m','n','o'],
  14. '':['p','q','r','s'],
  15. '':['t','u','v'],
  16. '':['w','x','y','z']
  17. }
  18. def dfs(index,temp):
  19. if index==self.len:
  20. self.res.append(temp)
  21. return
  22. num = digits[index]
  23. s = dict[num]
  24. for i in s:
  25. dfs(index+1,temp+i)
  26. self.res = []
  27. self.len = len(digits)
  28. dfs(0,"")
  29. return self.res

参考:

  1. def letterCombinations(digits):
  2. def dfs(num, string):
  3. if num == length:
  4. res.append(string)
  5. return
  6. for letter in dict[digits[num]]:
  7. dfs(num+1, string+letter)
  8.  
  9. dict = {'':['a','b','c'],
  10. '':['d','e','f'],
  11. '':['g','h','i'],
  12. '':['j','k','l'],
  13. '':['m','n','o'],
  14. '':['p','q','r','s'],
  15. '':['t','u','v'],
  16. '':['w','x','y','z']
  17. }
  18. res = []
  19. length = len(digits)
  20. dfs(0, '')
  21. 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. MySql 5.7关键字和保留字-附表

    现在使用navicat图形界面或者Hibernate做映射生成表的时候,渐渐的会忽视掉关键字这个问题,而后续也会不断的产生错误提示,一遍遍的查询代码无果,甚至开始怀疑人生,但是其实很多情况下只是使用了 ...

  2. 关于React中props与state的一知半解

    props props英文翻译是道具的意思,我个人理解为参数,如果我们将react组件看作是一个函数,那么props便是函数接收外部数据所使用的参数.props具有以下特性: 1.不可变(只读性) p ...

  3. 【ZIP】打包过滤指定目录和文件

    zip -r project.zip project/ -x@exclude.lst #目录过滤 # 直接目录,如 public public/* # 嵌套目录 如 node_modules */no ...

  4. ul列表li元素横排显示的IE兼容性问题

    目标: 使ul列表横排显示 现象: 谷歌OK,火狐竖排,IE竖排. 原因: ul原css代码: 首先,去除点号,list-style:none;为了使其横排,使用了display:contents;该 ...

  5. 常用命令之------ln

    当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在某个固定的目录,放上该文件,然后在 其它的目录下用ln命令链接(link)它就可以,不必重复的 ...

  6. html中自定义上传文件的样式

    <script> $(function(){ $("#avatsel1").click(function(){ $("input[type='file']&q ...

  7. git提示Please enter a commit message to explain why this merge is necessary

    Please enter a commit message to explain why this merge is necessary. 请输入提交消息来解释为什么这种合并是必要的(提交信息) gi ...

  8. MySQL不常用、易忽略的小知识

    笔者从事开发也有一段时间了,关于数据库方面的一些小知识在这里总结一下 1.count(*),count(1)与count(column)区别 count(*)对行的数目进行计算,包含NULL coun ...

  9. oracle基本语句(第七章、数据库逻辑对象管理)

    索引.实体化视图.簇.散列簇.序列.同义词 1.创建表 CREATE TABLE <表名>(<列名1> <数据类型>,……); CREATE GLOBAL TEMP ...

  10. CSP-S2019游记&拆塔记

    不是拆广州塔 Day -inf 四套NOI模拟降智 Day0 拆了一发新新 本来想复习小圆脸结果拆了3h最后还没带任意门 没有帘子可还行 第一天由于没发现被子可以抽出来就没睡好 Day1 8:30开考 ...