// 双指针办法对数组去重 避免复杂度O(n^2)不可用
function unique2(arr) {
let res = []
const length = arr.length;
if (length === 0) return res
let i = 0 // 头
let j = length - 1 // 尾
while (i < j) {
const n1 = arr[i]
const n2 = arr[j]
if (n1 !== n2) {
i++
j--
} else {
res.push(n1)
break
}
}
return res
}
console.log(unique2([1, 8, 2, 3, 6, 3, 5, 2, 4, 4]));