Letter Combinations of a Phone Number (电话号码字母组合) 【leetcode】
来源:互联网 发布:德州金蝶软件 编辑:程序博客网 时间:2024/05/16 04:35
题目:
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"].
题意就是按照给定的字符序列,找出所有可能的字母组合;
先把数字对于的字母集合存起来,用dfs遍历所有情况。
string num[10];char str[1000];vector<string>result;void hehe(string &digits,int i,int len){ if(i==len) { str[len]='\0'; string temp=str; result.push_back(temp); return; } int index=digits[i]-'0'; for(int j=0;j<num[index].size();++j) { str[i]=num[index][j]; hehe(digits,i+1,len); }}class Solution {public: vector<string> letterCombinations(string digits) { int len=digits.size(); result.clear(); num[2]="abc"; num[3]="def"; num[4]="ghi"; num[5]="jkl"; num[6]="mno"; num[7]="pqrs"; num[8]="tuv"; num[9]="wxyz"; hehe(digits,0,len); return result; }};
- Letter Combinations of a Phone Number (电话号码字母组合) 【leetcode】
- LeetCode 17 Letter Combinations of a Phone Number(电话号码的字母组合)
- [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合
- 425.Letter Combinations of a Phone Number-电话号码的字母组合(中等题)
- 17:Letter Combinations of a Phone Number(字母组合的电话号码)
- Letter Combinations of a Phone Number 电话号码的组合
- leetcode——Letter Combinations of a Phone Number 手机按键字母组合(AC)
- LeetCode 17 Letter Combinations of a Phone Number 数字转为字母组合
- Leetcode #17 Letter Combinations of a Phone Number Z9键盘字母组合解题小节
- LeetCode Letter Combinations of a Phone Number 经典组合问题
- 【LeetCode-面试算法经典-Java实现】【017-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
- 随机数生成问题
- JS实现投票
- VS2010环境下MFC,剪贴板“复制”程序。
- 【每天一个Linux命令】15. 搜索文件命令find
- 利用JS显示与隐藏层
- Letter Combinations of a Phone Number (电话号码字母组合) 【leetcode】
- 【MySQL数据库开发之一】Mac下配置安装数据库-MySQL
- C++中虚函数功能的实现机制
- 用!important解决IE和Mozilla的布局差别
- MD5算法原理
- Linux中的内存管理模型
- 黑马程序员------IO流(No.4)(打印流、序列流、管道流、RandomAccessFile、常用数据类型的操作流)
- 分享一个PHP的远程图片抓取函数
- ZigBee研究之旅(三)---CC2530的电源管理模块