[LeetCode] Letter Combinations of a Phone Number

时间:2022-04-12 08:56:24

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.

[LeetCode] Letter Combinations of a Phone Number

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.

好长时间没练题了,最近比较懒加之工作略忙,疏于思考,浪费了很多时间。这题想来想去知道是要深搜,但是都没动手实现,以为很复杂,其实是很典型的DFS模板,这和 Sudoku solver 的思路基本没有差别(其实和所有类似的题型都没差,几乎都用DFS模板一套就能出来)

void comboIter(string digits, int i, vector<string> &domains, string cur, vector<string> &result) {
if (i >= digits.size()) {
result.push_back(cur);
return;
}
char t = digits.at(i);
string domain = domains[t-''];
string old = cur;
for (char ele : domain) {
cur += ele;
comboIter(digits, i+, domains, cur ,result);
cur = old;
}
} vector<string> letterCombinations(string digits) {
vector<string> ret;
if (!digits.size()) return {""};
vector<string> domain = {"","","abc","def","ghi","jkl","mno","pqr","stu","vwxyz"};
comboIter(digits,,domain,"",ret);
return ret;
}

[LeetCode] Letter Combinations of a Phone Number的更多相关文章

  1. LeetCode&colon; Letter Combinations of a Phone Number 解题报告

    Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...

  2. &lbrack;LeetCode&rsqb;Letter Combinations of a Phone Number题解

    Letter Combinations of a Phone Number: Given a digit string, return all possible letter combinations ...

  3. &lbrack;LeetCode&rsqb; Letter Combinations of a Phone Number 电话号码的字母组合

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  4. LeetCode——Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  5. &lbrack;LeetCode&rsqb; Letter Combinations of a Phone Number(bfs)

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  6. LeetCode Letter Combinations of a Phone Number &lpar;DFS&rpar;

    题意 Given a digit string, return all possible letter combinations that the number could represent. A ...

  7. &lbrack;LeetCode&rsqb; Letter Combinations of a Phone Number 回溯

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  8. LeetCode Letter Combinations of a Phone Number 电话号码组合

    题意:给一个电话号码,要求返回所有在手机上按键的组合,组合必须由键盘上号码的下方的字母组成. 思路:尼玛,一直RE,题意都不说0和1怎么办.DP解决. class Solution { public: ...

  9. leetcode Letter Combinations of a Phone Number python

    class Solution(object): def letterCombinations(self, digits): """ :type digits: str : ...

随机推荐

  1. 2076 Problem F Quick Brown Fox

    题目描述 A pangram is a phrase that includes at least one occurrence of each of the 26 letters, ‘a’. . . ...

  2. HDU3987 Harry Potter and the Forbidden Forest(边数最少的最小割)

    方法1:两遍最大流.一遍最大流后,把满流边容量+1,非满流边改为INF:再求最小割即为答案. 我大概想了下证明:能构成最小割的边在第一次跑最大流时都满流,然后按那样改变边容量再求一次最小割,就相当于再 ...

  3. 用Firefly创建第一个工程

    原地址:http://blog.csdn.net/uxqclm/article/details/10382097 安装完成之后,在python script包中就存在 firefly-admin的工具 ...

  4. 两表关联更新&comma;用于update 回滚

    create table test1 as select * from dba_objects; create table test2 as select * from dba_objects; cr ...

  5. DTCoreText

    背景:使用DTCoreText实现epub阅读器的内容排版 基础准备:coretext,HTML+CSS渲染机制,epub文件格式 一:ios端epub实现:主要是两种,coretext,webvie ...

  6. Codeforces 1027F Session in BSU - 并查集

    题目传送门 传送门I 传送门II 传送门III 题目大意 有$n​$门科目有考试,第$i​$门科目有两场考试,时间分别在$a_i, b_i\ \ (a_i < b_i)​$,要求每门科目至少参加 ...

  7. Oracle DB 使用RMAN恢复目录

    • 对恢复目录和RMAN 资料档案库控制文件的使用进行比较• 创建和配置恢复目录• 在恢复目录中注册数据库• 同步恢复目录• 使用RMAN 存储脚本• 备份恢复目录• 创建虚拟专用目录 RMAN 资料 ...

  8. Spring Security 认证流程

    请求之间共享SecurityContext原因:

  9. centos7 Minimal安装没有ifconfig

    centos7 Minimal  安装后 ip addr 系统的网卡没有分配IP地址 网卡为ens33 cd /etc/sysconfig/network-scripts vi ifcfg-ens33 ...

  10. Sort-242&period; Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...