题解 | #查找重复元素#
查找重复元素
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;
} 