账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    (Javascript)LEETCODE题目,执行结果 & 本地环境可通过,提交代码时运行时错误,如何解决?
    46
    0

    具体问题,LEETCODE第17题(简单难度)
    https://leetcode-cn.com/probl...

    我的代码:

    /**
     * @param {string} digits
     * @return {string[]}
     */
    var letterCombinations = function(digits) {
        //1. 建立数字和字母的映射 2~9
        let map=['','','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']
        //2. 字符串转数组,使其可遍历  23=>[2,3] 
        let nums = digits.split('')
        //3. 保存数字映射后的内容 [2,3]=>['abc','def'] 
        let code = []
        nums.forEach(item=>{
            if(map[item]){
                code.push(map[item])
            }
        })
        let comb = (arr)=>{
            let tmp=[]
            for(let i=0;i<arr[0].length;i++){
                for(let j=0;j<arr[1].length;j++){
                    tmp.push(`${arr[0][i]}${arr[1][j]}`)
                }
            }
            arr.splice(0,2,tmp)
            if(arr.length>1){
                comb(arr)
            }
            else{
                return arr[0]
            }
            return arr[0]
        }
        return comb(code)
    };

    报错如下

    执行出错信息:
    Line 19: TypeError: Cannot read property 'length' of undefined

    执行结果 & 本地环境可通过,提交代码时运行时错误,如何解决?

    2
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    • 血·魅 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部