We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
When an array is given, each element of array is integer. Every element of array is appear twice, except for one. Find that one.
Using bitwise, we can remove repeated one. ex) 4 ^ 4 = 0, 1 ^ 4 ^ 4 = 1.
The code is below.
const singleNumber = function(nums) { let res = 0; nums.forEach(num => { res = num ^ res; }); return res; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Problem
When an array is given, each element of array is integer.
Every element of array is appear twice, except for one.
Find that one.
Solution
Using bitwise, we can remove repeated one.
ex) 4 ^ 4 = 0, 1 ^ 4 ^ 4 = 1.
The code is below.
The text was updated successfully, but these errors were encountered: