find the single integer
2022年5月1日小于 1 分钟
find the single integer
Question
Given an array of integers, all integers appear twice except one integer, could you quickly target it ?
const arr = [10, 2, 2 , 1, 0, 0, 10]
findSingle(arr) // 1
What is time & space cost of your approach ? Could you do better ?
Code
/**
* @param {number[]} arr
* @returns number
*/
function findSingle(arr) {
// your code here
}