zoukankan      html  css  js  c++  java
  • leetcode 17. *的字母组合

    var letterCombinations = function(digits) {
        if (!digits || digits === ' ') return []
        let alpList = ['abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']
        let res = []
        let len = digits.length - 1
        let tmpStr = []
        for(let i = 0;i <= len;i++){
            let num = digits[i]-2
            let alpCount = alpList[num].length - 1
            tmpStr = []
            let listLen = res.length - 1
            if(i === 0){
                for(let j = 0;j<=alpCount;j++){
                    res.push(alpList[num][j])
                }
                continue
            }
            for(let k = 0;k<=listLen;k++){
                for(let j = 0;j<=alpCount;j++){
                    tmpStr.push(res[k]+alpList[num][j])
                }
            }
            res = tmpStr
        }
        return res
    };

    思路:排列组合

  • 相关阅读:
    JAVA学习25天
    Java学习第24天
    Java学习第23天
    Java学习22天
    第3周
    Java21
    day23作业
    day23
    Typecho使用技巧
    搭建Typecho博客
  • 原文地址:https://www.cnblogs.com/AwenJS/p/12714734.html
Copyright © 2011-2022 走看看