17. Letter Combinations of a Phone Number
来源:互联网 发布:淘宝要好评 编辑:程序博客网 时间:2024/05/17 03:37
Given a digit string, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below.
Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.
do a dfs search to see all the combinations.
class Solution(object): def letterCombinations(self, digits): """ :type digits: str :rtype: List[str] """ NUMBER_HASH={'2':['a','b','c'], '3':['d','e','f'], '4':['g','h','i'], '5':['j','k','l'], '6':['m','n','o'], '7':['p','q','r','s'], '8':['t','u','v'], '9':['w','x','y','z'] } digit_length = len(digits) def dfs(number_length, string, result): if number_length == digit_length: result.append(string) return for letter in NUMBER_HASH[digits[number_length]]: dfs(number_length + 1, string + letter, result) result = [] if len(digits) == 0: return result dfs(0, '', result) return result
0 0
- 17.Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- Java 文件I/O常用API 以及上传下载路径问题汇总
- 机器学习系列(5)_从白富美相亲看特征选择与预处理(上)
- Https工具类
- xss 测试
- 学习使用MEAN开发RESTful WEB api,实现数据的CRUD
- 17. Letter Combinations of a Phone Number
- Android网络开发框架Retrofit(四:扩展篇,Retrofit+RxJava)
- Hessian
- 秒杀多线程第六篇 经典线程同步 事件Event
- Android起航系列第二章:为app添加action bar
- SQLSERVER 分布式事务开放
- UVA11997 K个最小和_优先队列&&K路合并
- C++ 输入与输出的学习
- 基于opencv的动画操作