leetcode-mid-backtracking-17. Letter Combinations of a Phone Number
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的更多相关文章
- leetcode个人题解——#17 Letter Combinations of a Phone Number
思路:用深搜遍历九宫格字符串,一开始做的时候发生了引用指向空地址的问题,后来发现是vector不能直接=赋值. class Solution { public: int len; ]={"a ...
- [LeetCode][Python]17: Letter Combinations of a Phone Number
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...
- 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 ...
- 刷题17. Letter Combinations of a Phone Number
一.题目说明 题目17. Letter Combinations of a Phone Number,题目给了下面一个图,输入一个字符串包括2-9,输出所有可能的字符组合. 如输入23所有可能的输出: ...
- 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合
Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...
- [leetcode 17]Letter Combinations of a Phone Number
1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...
- 【一天一道LeetCode】#17. Letter Combinations of a Phone Number
一天一道LeetCode (一)题目 Given a digit string, return all possible letter combinations that the number cou ...
- [leetcode]17. Letter Combinations of a Phone Number手机键盘的字母组合
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...
- 17. Letter Combinations of a Phone Number (backtracking)
Given a digit string, return all possible letter combinations that the number could represent. A map ...
随机推荐
- MySql 5.7关键字和保留字-附表
现在使用navicat图形界面或者Hibernate做映射生成表的时候,渐渐的会忽视掉关键字这个问题,而后续也会不断的产生错误提示,一遍遍的查询代码无果,甚至开始怀疑人生,但是其实很多情况下只是使用了 ...
- 关于React中props与state的一知半解
props props英文翻译是道具的意思,我个人理解为参数,如果我们将react组件看作是一个函数,那么props便是函数接收外部数据所使用的参数.props具有以下特性: 1.不可变(只读性) p ...
- 【ZIP】打包过滤指定目录和文件
zip -r project.zip project/ -x@exclude.lst #目录过滤 # 直接目录,如 public public/* # 嵌套目录 如 node_modules */no ...
- ul列表li元素横排显示的IE兼容性问题
目标: 使ul列表横排显示 现象: 谷歌OK,火狐竖排,IE竖排. 原因: ul原css代码: 首先,去除点号,list-style:none;为了使其横排,使用了display:contents;该 ...
- 常用命令之------ln
当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在某个固定的目录,放上该文件,然后在 其它的目录下用ln命令链接(link)它就可以,不必重复的 ...
- html中自定义上传文件的样式
<script> $(function(){ $("#avatsel1").click(function(){ $("input[type='file']&q ...
- 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 ...
- MySQL不常用、易忽略的小知识
笔者从事开发也有一段时间了,关于数据库方面的一些小知识在这里总结一下 1.count(*),count(1)与count(column)区别 count(*)对行的数目进行计算,包含NULL coun ...
- oracle基本语句(第七章、数据库逻辑对象管理)
索引.实体化视图.簇.散列簇.序列.同义词 1.创建表 CREATE TABLE <表名>(<列名1> <数据类型>,……); CREATE GLOBAL TEMP ...
- CSP-S2019游记&拆塔记
不是拆广州塔 Day -inf 四套NOI模拟降智 Day0 拆了一发新新 本来想复习小圆脸结果拆了3h最后还没带任意门 没有帘子可还行 第一天由于没发现被子可以抽出来就没睡好 Day1 8:30开考 ...