LeetCode--Letter Combinations of a Phone Number(Python)
来源:互联网 发布:数据库子查询语句 编辑:程序博客网 时间:2024/06/06 00:25
题目:
给定一串数字字符,返回手机九建返回的可能的字符串集合。样例如下
解题思路:
直接按照数字顺序将字符串进行迭代。使用哈希表(即python中的字典)提高效率。
代码(Python):
class Solution(object): def letterCombinations(self, digits): """ :type digits: str :rtype: List[str] """ if digits=='': return [] List = [''] Dict = {'0':' ','1':'*','2':'abc','3':'def','4':'ghi','5':'jkl','6':'mno','7':'pqrs','8':'tuv','9':'wxyz'} def read_char(c,List): R_list = [] for i in Dict[c]: for j in List: R_list.append(j+i) return R_list for i in range(len(digits)): List = read_char(digits[i],List) return List
阅读全文
0 0
- LeetCode--Letter Combinations of a Phone Number(Python)
- 【LeetCode with Python】 Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number Leetcode Python
- leetcode 016 Letter Combinations of a Phone Number(Python)
- [leetcode: Python]17. Letter Combinations of a Phone Number
- 【Leetcode】【python】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
- docker swarm model模式下的每个容器夸主机互通
- motan小结
- Android图表库MPAndroidChart(十四)——在ListView种使用相同的图表
- Python+OpenCV+pytesseract 识别 银行卡号
- 利用mk-table-checksum监测Mysql主从数据一致性操作记录
- LeetCode--Letter Combinations of a Phone Number(Python)
- onActivityResult立即执行分析
- 关于android 多文件分享的问题
- 文章标题
- Spark 堆外内存
- tp3.2中jquery查询订单信息
- VMware虚拟机的三种网络模式
- SQL SELECT语句
- volatile关键字实现原理