Mid From PDF Coding C# Coding Interview

Find the single non-repeated element in an array where every other?

element appears twice

public int SingleNonRepeated(int[] nums) {
int result = 0;
foreach (int num in nums) {
result ^= num;
}
return result;
}

Explanation:

XOR of a number with itself is 0; XOR with 0 is the number. So duplicates cancel out,

leaving the unique number.

Follow on:

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details