Letter Combinations of a Phone Number
来源:互联网 发布:java接口的实现 编辑:程序博客网 时间:2024/05/14 16:27
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"].
class Solution {public: void dfs(string table[],vector<string>&vec,int dep, int max, string &s, string cur){ string str = table[s.at(dep) - '2'];for(int i = 0; i < str.length(); i++){ string next = cur + str.at(i); if(dep == max - 1){ vec.push_back(next); } else{ dfs(table,vec,dep + 1, max, s, next); } } } vector<string> letterCombinations(string digits) { vector<string>vec; if(digits.length() <= 0){ vec.push_back(""); return vec; }string table[8] = {"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; dfs(table,vec,0,digits.size(),digits,""); return vec; } };
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
- 黑马程序员--Java高新技术--JDK1.5新特性(上)
- apkplug主题切换功能之主题包打包编译-07
- 手机SIM卡揭密
- java环境变量配置
- day75内部类之状态,使用理由。
- Letter Combinations of a Phone Number
- 类的生命周期
- ckeditor for java 的配置教程
- FreeMarker教程
- oracle数据库中在n个字段值相同时给另一字段值合并用逗号隔开
- 在VMware虚拟机上安装Ubuntu 10.04
- 手机SIM内部资料介绍
- oc学习笔记(四)面向对象-类的三大特性:封装,继承,多态
- 我是一只小小鸟