-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17.js
28 lines (26 loc) · 890 Bytes
/
17.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Letter Combinations of a Phone Number
var letterCombinationsAux = function(digits, outputArray, aString, aDictionary) {
if (aString.length === digits.length) {
outputArray.push(aString);
}
else {
let current_number = digits.charAt(aString.length);
let possible_letters = aDictionary[current_number];
for (let i = 0; i < possible_letters.length; i++) {
letterCombinationsAux(digits, outputArray, aString + possible_letters.charAt(i), aDictionary);
}
}
}
/**
* @param {string} digits
* @return {string[]}
*/
var letterCombinations = function(digits) {
if (digits === "") {
return [];
}
const output = [];
const dict = {"2": "abc", "3": "def", "4": "ghi", "5": "jkl", "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz"};
letterCombinationsAux(digits, output, "", dict);
return output;
};