Clean ES6


  • 0
    const keypad = [ [],
        [           ], ['a','b','c'], ['d','e','f'],
        ['g','h','i'], ['j','k','l'], ['m','n','o'],
        ['p','q','r','s'], ['t','u','v'], ['w','x','y','z']
    ];
    
    let digits = null;
    let output = null;
    
    letterCombinations = (d) => {
        if(d === "") return [];
        
        digits = d.split('').map(parseFloat);
        output = [];
        
        permute(0, "");
        return output;
    };
    
    permute = (char_idx, current) => {
        if(char_idx >= digits.length)
            return output.push(current);
        
        let num = digits[char_idx];
        keypad[num].forEach( letter => permute( char_idx + 1, current + letter ) );
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.