Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

电话号码的字母组合 #438

Open
Pcjmy opened this issue Jan 29, 2023 · 1 comment
Open

电话号码的字母组合 #438

Pcjmy opened this issue Jan 29, 2023 · 1 comment

Comments

@Pcjmy
Copy link
Contributor

Pcjmy commented Jan 29, 2023

No description provided.

@lxy-Jason
Copy link
Contributor

/**
 * @param {string} digits
 * @return {string[]}
 */
var letterCombinations = function(digits) {
    const len = digits.length
    const arr = ['','','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']
    if(!len) return []
    if(len === 1) return arr[digits].split('')

    const res = [], path = []
    backtracking(digits,len,0)
    return res

    function backtracking(n,len,arrIndex){
        if(path.length === len){
            res.push(path.join(""))
            return
        }
        for(const v of arr[n[arrIndex]]){
            path.push(v)
            backtracking(n,len,arrIndex + 1)
            path.pop()
        }
    }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants