leetcode 17:Letter Combinations of a Phone Number(15-10-5)
来源:互联网 发布:windows photoviewer 编辑:程序博客网 时间:2024/05/18 02:00
1.Problem
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.
2.Solution
class Solution {public:vector<string> letterCombinations(string digits) { vector<string> res; if(digits[0]=='\0') {return res;} string charmap[10] = {"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; res.push_back(""); for (int i = 0; i < digits.size(); i++) { vector<string> tempres; string chars = charmap[digits[i] - '0']; for (int c = 0; c < chars.size();c++) for (int j = 0; j < res.size();j++) tempres.push_back(res[j]+chars[c]); res = tempres; } return res;}};
0 0
- leetcode 17:Letter Combinations of a Phone Number(15-10-5)
- 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
- [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
- 无题(四):分割字符串(运用二维数组)
- why delete Scene crash!
- 论文返修(response letter)一些很有用的套话
- 关于Trimmomatic
- 优化Myeclipse10 Building Workspace速度慢等
- leetcode 17:Letter Combinations of a Phone Number(15-10-5)
- C#删除和清空文件夹的程序
- unity官方demo学习之Stealth(二十四)敌人AI
- Java编程之TreeSet排序两种解决方法(1)元素自身具备比较功能,元素需要实现Comparable接口覆盖compare(2)创建根据自定义Person类的name进行排序的Comparator
- iOS编程------- UITableViewController
- 前景提取--Subspace learning models
- SQL Server DDL触发器运用
- 15 个必须知道的 Chrome 开发工具技巧
- 黑马程序员—常见API