【leetcode】Letter Combinations of a Phone Number
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.
回溯法递归调用即可:
class Solution { public: vector<string> letterCombinations(string digits) { vector<string> num2string(); num2string[]=""; num2string[] = ""; num2string[] = "abc"; num2string[] = "def"; num2string[] = "ghi"; num2string[] = "jkl"; num2string[] = "mno"; num2string[] = "pqrs"; num2string[] = "tuv"; num2string[] = "wxyz"; vector<string> result; string tmp=""; combination(digits,,tmp,num2string,result); return result; } void combination(string &digits,int index,string tmp,vector<string> &num2string,vector<string> &result) { if(index==digits.length()) { result.push_back(tmp); return; } string mapString=num2string[digits[index]-'']; for(int i=;i<mapString.length();i++) { tmp.push_back(mapString[i]); combination(digits,index+,tmp,num2string,result); tmp.pop_back(); } } };
【leetcode】Letter Combinations of a Phone Number的更多相关文章
- 【leetcode】 Letter Combinations of a Phone Number(middle)
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 【Leetcode】【Medium】Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- Leetcode 17. Letter Combinations of a Phone Number(水)
17. Letter Combinations of a Phone Number Medium Given a string containing digits from 2-9 inclusive ...
- 【JAVA、C++】LeetCode 017 Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 【leetcode刷题笔记】Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 【LeetCode】77. Combinations 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:递归 方法二:回溯法 日期 题目地址:htt ...
- [leetcode 17]Letter Combinations of a Phone Number
1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...
- [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合
Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...
- Java [leetcode 17]Letter Combinations of a Phone Number
题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...
随机推荐
- Java基础-四要素之一《抽象》(接口)
抽象的概念就是抽象出共同属性:成员变量和方法 定义抽象使用abstract关键字定义抽象类和方法 抽象类 abstract class 包含抽象方法的类,叫抽象类. 所以抽象类可以有private等多 ...
- C#给文件夹添加权限
//==== //添加权限 private void SetAttributes(string folder) { if (folder == "" || !Directory.E ...
- 【Gym 100015A】Another Rock-Paper-Scissors Problem
题 题意 Sonny出石头剪刀布的猜拳策略是 先出R,然后每连续两段都是打败前一段的出拳, 现在问你第n回合打败他要出什么. 分析 他的策略 R P S PSR SRP PSRSRPRPS SRPR ...
- 【HDU 5363】Key Set
题 Description soda has a set $S$ with $n$ integers $\{1, 2, \dots, n\}$. A set is called key set if ...
- 【Matplotlib】图例分开显示
作图时图例往往都会出现一个图例框内,如果需要不同类型的图例分别显示,比如显示两个图例. 基本上,出现两个图例的话,需要调用两次 legend .第一次调用,你需要将图例保存到一个变量中,然后保存下来. ...
- Type-Length-Value编码
Within data communication protocols, optional information may be encoded as a type-length-value or T ...
- Ext comboBox的remote和local的区别
remote模式下不能使用模糊查询的功能 而local模式下可以实现模糊查询的功能 如果非要实现模糊查询的功能,最好就是提前把数据查询出来,缓存到本地,然后再用local模式 且,改个属性,改成可编辑 ...
- javaIO(二)
在程序中所有的数据都是以流的方式进行传输或保存的,程序需要数据时要使用输入流读取数据,而当程序需要将一些数据保存起来时,就要使用输出流. 在java.io包中流的操作主要有字节流.字符流两大类,两类都 ...
- iOS开发的那些坑
最近重新拿起了iOS的开发,使用OC和Swift混编,碰到了一些比较棘手的问题,在这里记录下来,方便自己以后或他人不再入坑.这篇文章的内容包含: UITableViewCell的真实结构在iOS的环境 ...
- iOS应用支持IPV6
一.IPV6-Only支持是啥? 首先IPV6,是对IPV4地址空间的扩充.目前当我们用iOS设备连接上Wifi.4G.3G等网络时,设备被分配的地址均是IPV4地址,但是随着运营商和企业逐渐部署IP ...