λ¬Έμ
νμ΄ κ³Όμ
ν΄λν° μνμ μ΄μ©ν΄μ λ§λ€ μ μλ λ¬Έμμ΄μ λͺ¨λ μ°Ύλ λ°±νΈλνΉ
λ¬Έμ μ
λλ€.
κ° μ«μλ³λ‘ ν λΉλ λ¬Έμλ€μ ννν΄μ£Όλ λ€μν λ°©λ²λ€ (Map, Object λ±
) μ΄ μμ§λ§
μ λ λ°°μ΄μ μΈλ±μ€λ‘ μ κ·Όνλ λ°©λ²μ μ¬μ©νμ΅λλ€.
μ«μλ‘ μ΄λ£¨μ΄μ§ μ£Όμ΄μ§ μ
λ ₯ λ¬Έμμ΄μ ν μλ¦¬μ© μννλ©° λ§λ€ μ μλ λͺ¨λ λ¬Έμμ΄μ μ¬κ·νΈμΆλ‘ μμ±νλ©΄ λ©λλ€.
μ½λ
/**
* @param {string} digits
* @return {string[]}
*/
const buttons = [
0,
0,
"abc",
"def",
"ghi",
"jkl",
"mno",
"pqrs",
"tuv",
"wxyz",
];
var letterCombinations = function (digits) {
if (!digits.length) return [];
function dfs(idx, selected, answer) {
if (idx === digits.length) {
answer.push(selected.join(""));
return;
}
for (let c of buttons[parseInt(digits[idx])]) {
selected.push(c);
dfs(idx + 1, selected, answer);
selected.pop();
}
}
const answer = [];
dfs(0, [], answer);
return answer;
};
λ°μν
'π algorithm > leetcode' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
LeetCode 787 - Cheapest Flights Within K Stops (Medium) (0) | 2021.03.02 |
---|---|
LeetCode 417 - Pacific Atlantic Water Flow (Medium) (0) | 2021.03.02 |
LeetCode 230 - Kth Smallest Element in a BST (Medium) (0) | 2021.03.02 |
LeetCode 198 - House Robber (Easy) (0) | 2021.03.02 |
LeetCode 22 - Generate Parentheses (Medium) (0) | 2021.03.02 |
π¬ λκΈ