leetcode17-根据数字找到可能的按键字母组合
2017-11-13 14:33
489 查看
/* 这个解法是比较巧妙的 */ vector<string> letterCombinations(string digits) { vector<string> res; string charmap[10] = { "0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" }; res.push_back("");//此时res的size=1 //一个组合string的长度肯定小于digits.size() for (int i = 0; i < digits.size(); i++) { //每次tempres都是新的,所以最后res中string都是size长度的 vector<string> tempres; //digits[i] - '0'获得数组下标索引:0,1,2,3.... //因此chars就取得了 "abc"或者"def"或者... string chars = charmap[digits[i] - '0']; //动态增长的两层循环,每次循环完了,res.size会增加 for (int c = 0; c < chars.size(); c++) for (int j = 0; j < res.size(); j++) { //每次为res中的每个字符串末尾添加一个新的字符 tempres.push_back( res[j] + chars[c] ); } res = tempres; cout << "res.size = " << res.size() << endl; } return res; }
相关文章推荐
- LeetCode 17 Letter Combinations of a Phone Number 数字转为字母组合
- 给定一个数字字符串,返回数字可能表示的所有可能的字母组合。数字与字母的对应关系和手机按键对应
- 给定一个数字字符串,返回数字可能表示的所有可能的字母组合。数字与字母的对应关系和手机按键对应。
- LeetCode17——Letter Combinations of a Phone Number(手机几个按键对应的字母(符号)组合)
- 每天一道LeetCode-----找到有多少个组合加起来和是n,每个组合的数字只能是1或者2
- leetcode——Letter Combinations of a Phone Number 手机按键字母组合(AC)
- 字母a-z,数字0-9,现需要其中任意3个作为密码,请输出所有可能组合。
- leetCode 17.Letter Combinations of a Phone Number(电话数字对应的字母组合) 解题思路和方法
- 17. Letter Combinations of a Phone Number(根据手机按键求字母的组合)
- leetcode-31 Next Permutation 数字排列组合找到下一个更大值
- Letter Combinations of a Phone Number:给定数字求出对应的多个字母的组合可能问题
- LeetCode 17 Letter Combinations of a Phone Number(电话号码的字母组合)
- Leetcode: LetterCombinationsofaPhoneNumber 根据手机按键,给出所有可能的字符串
- 数字字符串转换为字母组合的种类数 动态规划
- 论是否可能找到一种独特技术指标的组合形成自己的交易系统
- 随机给定10个小于10的数字(出现的数字可能重复),从其中取出3个各不相同的数字可组合出多个不同的3位数,请输出这些3位数中最大的那个3位数
- 【程序17】题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
- java生成随机数字和字母组合
- jQuery 密码验证 字母加数字或符号的组合密码,不能单独使用数字、字母或字符
- 输入数字,返回数字代表的字母的所有组合