Letter Combinations of a Phone Number
来源:互联网 发布:淘宝严查刷单时间 编辑:程序博客网 时间:2024/06/05 03:59
Letter Combinations of a Phone Number
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.
题目很简单了,就是按每一位遍历,组合。
vector<string> letterCombinations(string digits) { vector<string> vec, phone(10); phone[2] = "abc"; phone[3] = "def"; phone[4] = "ghi"; phone[5] = "jkl"; phone[6] = "mno"; phone[7] = "pqrs"; phone[8] = "tuv"; phone[9] = "wxyz"; letters(phone, 0, "", vec, digits); return vec; } void letters(vector<string> &phone, int num, string str, vector<string> &vec, string digits){ if(num == digits.size()){ vec.push_back(str); return; } int c = digits[num] - '0'; for(int i = 0; i < phone[c].size(); i++){ letters(phone, num+1, str + phone[c][i], vec, digits); } }
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
- Hive修改表语句
- 面向对象--设计模式概览
- 一个关于webservice的Axis问题 Processing file deploy.wsdd Exception: deploy.wsdd (系统找不到指定的文件。)
- 英语学习平台
- FFmpeg浅尝辄止(四)——音频的解码和编码
- Letter Combinations of a Phone Number
- 20140608 learn by Ruby on Rails Tutorial
- 2014亚洲移动通信博览会,华为caas开放平台与你相约仲夏上海
- java 读取并保存excel中的图片
- 面向对象--介绍
- is Mogs safe for buying aion kinah
- 使用NSClassFromString
- swift学习三:?和!理解
- 通过profile绑定执行计划