Letter Combinations of a Phone Number
来源:互联网 发布:seo自动 编辑:程序博客网 时间:2024/06/10 16:46
class Solution {
public:
vector<string> letterCombinations(string digits) {
map<int,string>imap;
vector<string>s={" ","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
string temp;
vector<string>result;
if(digits.empty()) return result;
int len=digits.size();
dfs(0,s,len,temp,result,digits);
return result;
}
void dfs(int i,vector<string> &s,int len,string &temp,vector<string>&result,string &digits) //不能加引用; int &i 和int &len;
{
if(i==len) { result.push_back(temp);
return;}
string s1=s[digits[i]-'0'];
for(int j=0;j<s1.size();j++)
{
temp+=s1[j];
dfs(i+1,s,len,temp,result,digits);
temp.pop_back();
}
}
};
非递归;
- 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
- LeetCode18: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
- 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
- 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:Rectangle Area
- Python语法糖-装饰器
- python requests的安装与简单运用
- 算法设计与分析之入门篇(1.1算法概述)——什么是算法
- Letter Combinations of a Phone Number
- angular.extend方法
- linux服务器集群间建立ssh信任关系
- ASP.NET MVC+Bootstrap 实现短信验证
- cocos2dx 图片内存优化之从200M到50M
- ssh常用用法小结
- 【leetcode】Remove Element【java】
- HDU 1671 Phone List(字典树)
- ZOJ 1002 Fire Net【dfs】