LeetCode17. Letter Combinations of a Phone Number
来源:互联网 发布:miui优化 编辑:程序博客网 时间:2024/04/29 18:28
题目链接:
https://leetcode.com/problems/letter-combinations-of-a-phone-number/
题目描述:
给一个数字字符串,和一个数字的映射表,找出所有的字母组合。顺序可任意。
Input:Digit string “23”
Output: [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”].
题目分析:
递归来解,对当前已经找到的字符串,递归剩下的字符串。
代码:
class Solution {public: vector<string> s={ " ","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; vector<string> res; int n; void fun(string ss,string digits,int idx){ if (idx == n){ res.push_back(ss); return; } int j = digits[idx] - '0'; for (int i = 0; i<s[j].size(); i++){ string sss = ss; ss += s[j][i]; fun(ss, digits, idx + 1); ss = sss; } } vector<string> letterCombinations(string digits) { n=digits.size(); if(n==0){ return res; } string ss=""; fun(ss,digits,0); return res; }};
0 0
- [LeetCode17]Letter Combinations of a Phone Number
- LeetCode17:Letter Combinations of a Phone Number
- leetcode17 Letter Combinations of a Phone Number
- LeetCode17:Letter Combinations of a Phone Number
- leetcode17---Letter Combinations of a Phone Number
- LeetCode17. Letter Combinations of a Phone Number
- leetcode17:Letter Combinations of a Phone Number
- LeetCode17. Letter Combinations of a Phone Number
- leetcode17. Letter Combinations of a Phone Number
- leetcode17 Letter Combinations of a Phone Number
- [Java]LeetCode17 Letter Combinations of a Phone Number
- LeetCode17. Letter Combinations of a Phone Number可能是世界上最简明的解法了
- LeetCode17 17. Letter Combinations of a Phone Number My Submissions QuestionEditorial Solution
- LeetCode17 Letter Combinations of a Phone Number(Python and Java)
- LeetCode17——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
- Mat类的成员函数(中文+英文)
- 简笔画~公鸡
- 220,抽屉效果
- win7虚拟机里面windows xp上网设置问题
- 人工智能和机器学习领域开源项目
- LeetCode17. Letter Combinations of a Phone Number
- UVA 10820 Send a Table(欧拉函数)
- 创意的市场因素
- 创意的市场因素
- 简笔画~鸭子
- R下的GUI方案
- 221,多线程基础
- 简笔画~猴子
- 关于区块链的一些思考