手机按键组合问题
来源:互联网 发布:淘宝卖家新增运费模板 编辑:程序博客网 时间:2024/04/29 19:36
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 {private: map<char, vector<char> > dict; vector<string> ret;public: void createDict() { dict.clear(); dict['2'].push_back('a'); dict['2'].push_back('b'); dict['2'].push_back('c'); dict['3'].push_back('d'); dict['3'].push_back('e'); dict['3'].push_back('f'); dict['4'].push_back('g'); dict['4'].push_back('h'); dict['4'].push_back('i'); dict['5'].push_back('j'); dict['5'].push_back('k'); dict['5'].push_back('l'); dict['6'].push_back('m'); dict['6'].push_back('n'); dict['6'].push_back('o'); dict['7'].push_back('p'); dict['7'].push_back('q'); dict['7'].push_back('r'); dict['7'].push_back('s'); dict['8'].push_back('t'); dict['8'].push_back('u'); dict['8'].push_back('v'); dict['9'].push_back('w'); dict['9'].push_back('x'); dict['9'].push_back('y'); dict['9'].push_back('z'); } void dfs(int dep, int maxDep, string &s, string ans) { if (dep == maxDep) { ret.push_back(ans); return; } for(int i = 0; i < dict[s[dep]].size(); i++) dfs(dep + 1, maxDep, s, ans + dict[s[dep]][i]); } vector<string> letterCombinations(string digits) { // Start typing your C/C++ solution below // DO NOT write int main() function ret.clear(); createDict(); dfs(0, digits.size(), digits, ""); return ret; }};
0 0
- 手机按键组合问题
- 手机按键
- leetcode——Letter Combinations of a Phone Number 手机按键字母组合(AC)
- 17. Letter Combinations of a Phone Number(根据手机按键求字母的组合)
- 常用手机按键
- 手机按键震动
- 组合问题!
- 组合问题
- 组合问题
- 组合问题
- 组合问题
- 组合 问题
- 组合问题
- 组合问题
- 组合问题
- [转]手机按键生产工艺简介
- Android手机按键【监听】
- 手机按键学习笔记
- vs2010通过命令实现VS恢复默认设置
- 苹果WWDC:2016大会前瞻,好想去啊,只能网上看直播了
- Android Studio的优化/Gradle构建
- 算法11—判断一个树是不是二叉查询树
- “could not build module UIKit”问题的解决
- 手机按键组合问题
- 【Linux】进程调度算法
- jsp开发模式
- 16周阅读程序(1)
- swif 中如何使用NSClassFromString
- eclipse启动时jdk环境变量报错解决
- Resource ID #0x7f0d00bb type #0x12 is not valid
- java---什么是匿名对象
- Web前端教程-01.走进前端工程师的世界