题解 | #有重复项数字的全排列#

有重复项数字的全排列

https://www.nowcoder.com/practice/a43a2b986ef34843ac4fdd9159b69863

/**
 * 
 * @param num int整型一维数组 
 * @return int整型二维数组
 */
function permuteUnique( num ) {
    // write code here
    let res = [];
    let len = num.length;
    num.sort((a,b)=>{return(a-b)})
    const dfs=(temp,index,now)=>{
        if(temp.length==len){
            res.push([...temp]);
        };
        for(let i = 0;i<index.length;i++){
            if(index[i] == index[i-1]){
                continue
            }
            dfs([...temp,index[i]],index.slice(0,i).concat(index.slice(i+1)));
        }
        
    }
    dfs([],num);
    res.sort();
    console.log(Array.from(new Set(res)))
    return res;
}
module.exports = {
    pejavascript:void(0);rmuteUnique : permuteUnique
};
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 11:30
找工作7个月,投了7000封,3段世界五百强实习,才有一个offer,牛油们肯定比我强吧
码农索隆:不对不对不对,实习经历这么厉害,简历也没少投,问题出在哪呢
点赞 评论 收藏
分享
06-07 19:59
门头沟学院 C++
补药卡我啊😭:都快15年前的了还在11新特性
你的简历改到第几版了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 11:27
明天又是董事长面,啥时候是个头啊
积极向上的林同学:董事长亲自面试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务