leetcode 17. Letter Combinations of a Phone Number
来源:互联网 发布:纽约大学录取条件 知乎 编辑:程序博客网 时间:2024/05/21 10:42
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”].
class Solution(object): def output(self,digits,dep,cnt,ret,dictionary): if len(digits)>=1: if len(digits)==1: for j in dictionary[digits[0]]: dep[cnt]=j ret.append(''.join(dep[:])) else: for j in dictionary[digits[0]]: dep[cnt]=j self.output(digits[1:],dep,cnt+1,ret,dictionary) return ret def letterCombinations(self, digit): """ :type digits: str :rtype: List[str] """ dictionary={'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']} num=len(digit) dep=[0 for i in range(num)] cnt=0 ret=[] ans=self.output(digit,dep,cnt,ret,dictionary) return ans
0 0
- LeetCode: Letter Combinations of a Phone Number
- LeetCode Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [Leetcode] Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [LeetCode]Letter Combinations of a Phone Number
- LeetCode-Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- LeetCode - Letter Combinations of a Phone Number
- LeetCode:Letter Combinations of a Phone Number
- LeetCode | Letter Combinations of a Phone Number
- leetcode Letter Combinations of a Phone Number
- Leetcode: Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- leetcode: Letter Combinations of a Phone Number
- SDAU练习四 1005
- Debain软件源sources.list文件的更新
- Android Sudio 如何获取SHA1(开发版和发布版)
- Service生命周期
- 解决android4.0系统中菜单(Menu)添加Icon无效问题
- leetcode 17. Letter Combinations of a Phone Number
- 网页宽度自动适应手机屏幕宽度的方法
- java打包成可执行的jar或者exe的详细步骤
- Python 核心编程笔记_Chapter_3 Note_4 创建python文件(练习文件操作)
- cocoapods 最新安装教程
- Head First 设计模式笔记之------学习总结
- Python filter map reduce lambda Method detail
- 史上最全设计模式导学目录(完整版)
- jquery学习之取值