8.6—暴力枚举法—Letter Combinations of a Phone Number
来源:互联网 发布:linux下的下载工具 编辑:程序博客网 时间:2024/05/28 22:12
描述
Given a digit string, return all possible leer combinations that the number could represent.
A mapping of digit to leers (just like on the telephone buons) 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.
Given a digit string, return all possible leer combinations that the number could represent.
A mapping of digit to leers (just like on the telephone buons) 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.
#include<iostream>#include<vector>#include<string>#include<algorithm>using namespace std;vector<string> key_map = { " ", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };vector<string> LetterCombinations(string digits){vector<string> res;res.push_back("");if (digits.size() <= 0)return res;sort(digits.begin(), digits.end());string::iterator iter = unique(digits.begin(), digits.end());digits.erase(iter,digits.end());string mydigits;for (int i = 0; i < digits.size(); i++){if (digits[i] != '1')mydigits.push_back(digits[i]);}//===for (int i = 0; i < mydigits.size(); i++){vector<string> tempres;string chars = key_map[mydigits[i] - '0'];for (int j = 0; j < chars.size(); j++){for (int k = 0; k < res.size(); k++)tempres.push_back(res[k] + chars[j]);}res = tempres;}return res;}int main(){string digits = "123";vector<string> res = LetterCombinations(digits);for (int i = 0; i < res.size(); i++)cout << res[i] << endl;}
阅读全文
0 0
- 8.6—暴力枚举法—Letter Combinations of a Phone Number
- 8.6 Letter Combinations of a Phone Number
- LeetCode——Letter Combinations of a Phone Number
- leetcode 017 —— Letter Combinations of a Phone Number
- LeetCode题解——Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number —— Leetcode
- LeetCode——17. Letter Combinations of a Phone Number
- Leetcode——17. Letter Combinations of a Phone Number
- 算法系列——Letter Combinations of a Phone Number
- <17>——Letter Combinations of a Phone Number
- Algorithms—17.Letter Combinations of a Phone Number
- leetcode—Letter Combinations of a Phone Number
- 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
- 系统设计师必备技能与工具有哪些?
- easyui复选框树动态加载后台数据,实现自动选中数据库中数据。后台语言是.NET
- 8.5—暴力枚举法—Combinations
- 建立多线程的两种方法
- select poll 与epoll模型的总结
- 8.6—暴力枚举法—Letter Combinations of a Phone Number
- Android Camera结合Zxing优化扫码
- 算法编程题-判断一颗树中是否有与另一棵树拓扑结构完全相同的子树
- 使用Aspose.Cells实现后台输出Excel报表(C#)
- java反射的field.get(null)
- 11.1—分治法—Pow(x,n)
- Ubuntu16.04如何将普通用户提升至root权限
- caffe随记(四) --- mnist示例超详细讲解
- Mac 使用 80 端口