fixed linter errors
parent
6f6ef9d61a
commit
74d100eaf7
|
@ -1,14 +1,15 @@
|
||||||
// Problem: Given an array of integers, every element appears twice except for one. Find that single one.
|
// Problem: Given an array of integers,
|
||||||
|
// every element appears twice except for one. Find that single one.
|
||||||
// Space Complexity: O(1)
|
// Space Complexity: O(1)
|
||||||
// Time Complexity: O(n)
|
// Time Complexity: O(n)
|
||||||
|
|
||||||
function singleOccurringElement(arr) {
|
function singleOccurringElement(arr) {
|
||||||
let result = 0;
|
let result = 0;
|
||||||
for(let el of arr) {
|
for (const el of arr) {
|
||||||
result ^= el;
|
result ^= el;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const arr = [2, 5, 7, 3, 1, 8, 8, 9, 4, 2, 7, 1, 4, 9, 5];
|
const arr = [2, 5, 7, 3, 1, 8, 8, 9, 4, 2, 7, 1, 4, 9, 5];
|
||||||
console.log(singleOccurringElement(arr));
|
console.log(singleOccurringElement(arr));
|
||||||
|
|
Loading…
Reference in New Issue