Letter Combinations of a Phone Number
来源:互联网 发布:淘宝哪里取消申请退款 编辑:程序博客网 时间:2024/06/06 11:49
题目大意:给定一串数,要求转换成能表示它的字符串的所有形式。
解题思路:深度遍历
class Solution {public: vector<string> letterCombinations(string digits) { string d[10] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; vector<string> result; if(digits.size() == 0) { return result; } string str; dfs(result, str, 0, digits, d); return result; }private: void dfs(vector<string> &result, string &str, int index, const string &digits, string d[]) { if(index == digits.size()) { result.push_back(str); return; } int i = (int)(digits[index] - '0'); for(int k = 0; k < d[i].size(); k++) { str.push_back(d[i][k]); dfs(result, str, index + 1, digits, d); str.pop_back(); } }};
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
- 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
- 网站分析与优化
- 3.17
- Codeforces #257B Jzzhu and Sequences(矩阵快速幂)
- 程序猿的日常-5
- HDU 1016 - Prime Ring Problem [简单DFS]
- Letter Combinations of a Phone Number
- 《AngularJS权威教程》
- F - Flowers
- Android学习笔记の五
- 15 Wallpaper 之OnTouch OnIntercept dispatch事件机制
- Raising Modulo Numbers (poj 1995 快速幂水题)
- c和c++的一些训练题(9)(学生成绩管理系统)
- HDU 4549 M斐波那契数列(矩阵快速幂)
- poj 3185 The Water Bowls (高斯消元)