Skip to content

Instantly share code, notes, and snippets.

@jooyunghan
Created January 8, 2018 14:19
Show Gist options
  • Save jooyunghan/2d4beb3789c84583bb47477096b5e463 to your computer and use it in GitHub Desktop.
Save jooyunghan/2d4beb3789c84583bb47477096b5e463 to your computer and use it in GitHub Desktop.
var letterCombinations = function(digits) {
if (digits.length === 0) return [];
const result = [''];
const letters = ' ||abc|def|ghi|jkl|mno|pqrs|tuv|wxyz'.split('|');
for (const d of digits) {
for (const r of result.splice(0)) {
for (const l of letters[+d]) {
result.push(r + l);
}
}
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment