Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Finds element without a pair in an unsorted array of integers.
- * @param {array} A
- * @param {int} Element without a pair
- */
- // Brute-force solution (55% on codility)
- function solution(A) {
- for (let digit of A) {
- if(A.indexOf(digit) === A.lastIndexOf(digit)) {
- return digit;
- }
- }
- };
- // Elegant but hard to understand solution using Bitwise XOR operator (100% on codility)
- function solution(A) {
- let result = 0;
- for (let element of N) {
- result ^= element;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement