LeetCode
来源:互联网 发布:qq飞车数据异常 编辑:程序博客网 时间:2024/06/01 07:13
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"].
Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.
时间复杂度O(3^(digits.length())),空间复杂度O(1);
class Solution {public: vector<string> mie{"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; vector<string> ans; vector<string> letterCombinations(string digits) { if (digits == "") return ans; solve(digits, 0, ""); return ans; } void solve(string digits, int id, string cur) { if (id == digits.length()) { ans.push_back(cur); return; } int x = digits[id] - '0'; for (int i = 0; i < mie[x].length(); ++i) { solve(digits, id+1, cur+mie[x][i]); } }};
阅读全文
0 0
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- C/C++_多核多线程编程_互斥锁
- mysql存储过程简单示例
- js中的Node属性和方法
- git常用命令操作
- 机器学习(七)- logistic regression
- LeetCode
- Django学习中遇见的问题总结
- Loadrunner中socket基本函数的用法与区别
- Angular.js(二)
- java.lang.OutOfMemoryError: PermGen space
- 2-静态库的创建和使用
- 网络信息安全攻防平台脚本关快速口算
- UVA 122
- 7GOJ 23 fleet [主席树]