[leetcode] 17. Letter Combinations of a Phone Number 解题报告
来源:互联网 发布:记录梦话的软件 编辑:程序博客网 时间:2024/05/14 07:00
题目链接:https://leetcode.com/problems/letter-combinations-of-a-phone-number/
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.
思路:建一张表,简单的深搜。每次取那个数字的字母表的一个值。
代码如下:
class Solution {public: void DFS(string str, int k, string tem) { if(k >= str.size()) result.push_back(tem); if(!(str[k]>'1' && str[k]<= '9')) return; for(auto val: hash[str[k]-'0']) DFS(str, k+1, tem+val); } vector<string> letterCombinations(string digits) { if(digits.size() ==0) return {}; hash[2] = {'a', 'b', 'c'}; hash[3] = {'d', 'e', 'f'}; hash[4] = {'g', 'h', 'i'}; hash[5] = {'j', 'k', 'l'}; hash[6] = {'m', 'n', 'o'}; hash[7] = {'p', 'q', 'r', 's'}; hash[8] = {'t', 'u', 'v'}; hash[9] = {'w', 'x', 'y', 'z'}; DFS(digits, 0, ""); return result; }private: vector<string> result; unordered_map<int, set<char>> hash;};
0 0
- [leetcode] 17. Letter Combinations of a Phone Number 解题报告
- [Leetcode] 17. Letter Combinations of a Phone Number 解题报告
- leetcode解题报告17. 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 解题报告
- Letter Combinations of a Phone Number --leetcode解题报告
- [leetCode 解题报告]017. Letter Combinations of a Phone Number
- [leetCode 解题报告]080. Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number解题报告
- [leetcode javascript解题]Letter Combinations of a Phone Number
- leetcode解题方案--017--Letter Combinations of a Phone Number
- leecode 解题总结:17. 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
- SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
- LeetCode Remove Nth Node From End of List
- public void onClick(View arg0)
- 简单涉猎各种博弈
- Android防止APK被反编译和二次打包
- [leetcode] 17. Letter Combinations of a Phone Number 解题报告
- Linux系统运行的七个等级
- 获取Objc 类方法及属性的研究实现
- thinkphp-url地址影藏入口文件index.php
- js为元素增加流动边框效果
- 语言c++(index)
- python3 抓取必应bing首页图片作为桌面背景
- 基于Arduino的视频监控小车
- ArcGIS JavaScript API 4.0 beta 1