Letter Combinations Of A Number Phone

 1 var arr = [
 2     [],
 3     [],
 4     [‘a‘, ‘b‘, ‘c‘],
 5     [‘d‘, ‘e‘, ‘f‘],
 6     [‘g‘, ‘h‘, ‘i‘],
 7     [‘j‘, ‘k‘, ‘l‘],
 8     [‘m‘, ‘n‘, ‘o‘],
 9     [‘p‘, ‘q‘, ‘r‘, ‘s‘],
10     [‘t‘, ‘u‘, ‘v‘],
11     [‘w‘, ‘x‘, ‘y‘, ‘z‘]
12 ];
13
14 var letterCombinations = function(digits) {
15     if (digits.length < 1) {
16         return [];
17     }
18
19     if (digits.length === 1) {
20         return arr[digits[0]];
21     }
22
23     var ret = [],
24         listNow = arr[digits[0]],
25         listBehind = letterCombinations(digits.substring(1)),
26         lenBehind = listBehind.length;
27
28     for (var i = 0; i < listNow.length; i++) {
29         for (var j = 0; j < listBehind.length; j++) {
30             ret[i * lenBehind + j] = listNow[i] + listBehind[j];
31         }
32     }
33
34     return ret;
35 };
时间: 2024-08-03 14:20:14

Letter Combinations Of A Number Phone的相关文章

17. 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", &q

Letter Combinations of a Phone Number

1. Question 给一个数字字符串,按照电话上各个数字对应的字母,返回该字符串代表的所有可能的字母组合. 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 stri

【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" Outpu

leetcode第18题--Letter Combinations of a Phone Number

Problem: 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&

LeetCode: Letter Combinations of a Phone Number [018]

[题目] 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"

【LeetCode】17. 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", &q

LeetCode17 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"

[string]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", &q

LeetCode #17 Letter Combinations of a Phone Number (M)

[Problem] 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