题解 | #查找重复元素#

查找重复元素

http://www.nowcoder.com/practice/871a468deecf453589ea261835d6b78b

hash表

function duplicates(arr) {
    const target = [];
    const map = new Map();
    arr.forEach(v => {
        if(map.has(v) && !target.includes(v)) {
            target.push(v);
        } else {
            map.set(v, v);
        }
    });
    return target;
}
全部评论

相关推荐

包行:平时怎么刷算法题的哇,字节的手撕听说都很难
字节跳动工作体验
点赞 评论 收藏
分享
纯真的河老师在喝茶:第一个是这个时间点岗位少,第二个是这个简历重复度太高了,10个有9个简历差不多的
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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