leetcode 17. Letter Combinations of a Phone Number
来源:互联网 发布:vue.js 2.0中文文档 编辑:程序博客网 时间:2024/06/15 13:29
常见DFS题,好久没做了,有点生疏
dfs最常见的就是
dfs()
{
if(到达边界条件)
输出结果到答案
for(?;?;?)
{
给某全局变量赋值
dfs()
解除全局变量赋值
}
}
class Solution {public:string str[10]={" ","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};vector<string> ans;string dfs_str;void dfs(string digits,int k){int num,str_len,len,i;string now_s;str_len=digits.length();if(k==str_len) //若等于长度,则ans加一个字符串{ans.push_back(dfs_str);return ;}num=digits[k]-'0';now_s=str[num];len=now_s.length();for(i=0;i<len;i++) { dfs_str+=now_s[i]; //dfs_str加一个字符dfs(digits,k+1);dfs_str=dfs_str.substr(0,k); //减一个字符}}vector<string> letterCombinations(string digits){ if(digits.size()==0) return ans;dfs(digits,0);return ans;}};
0 0
- 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
- 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
- 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
- JAVA抽象类和接口
- Cash Machine poj 1276
- Tomcat 简介(1)
- GreenDAO使用
- DataStructure_4.Stack & Queue
- leetcode 17. Letter Combinations of a Phone Number
- Android 5.0 之CardView
- windows下面的php+mysql+nginx
- 2一切都是对象-Java编程思想
- Codeforces Round #164 (Div. 2) A. Games 【水题】
- VS2012常用快捷键
- 101. Symmetric Tree
- LeetCode No.3 Longest Substring Without Repeating Characters
- codeforces C. Simple Strings