Skip to content

Latest commit

 

History

History
39 lines (24 loc) · 1.35 KB

2019-06-18.md

File metadata and controls

39 lines (24 loc) · 1.35 KB

每日一题 - Letter Combinations Of A Phone Number

信息卡片

题目描述

Given a string containing digits from 2-9 inclusive, 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. Note that 1 does not map to any letters.



Example:

Input: "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. 如果大家之前看过我仓库的话,应该知道这种题目有一个通用的解题框架和模板。 今天我们就来巩固下这个解题思路。 题目简单直接我就不说了,如果没有明白的可以移步到我的仓库中继续看。 比如 https://github.com/azl397985856/leetcode/blob/master/problems/39.combination-sum.md 就用到了这种方法(回溯法)

参考代码: https://github.com/azl397985856/leetcode/blob/master/daily/answers/17.letter-combinations-of-a-phone-number.js

其他优秀解答

暂无