This post is completed by 1 user
|
Add to List |
Find a Number occurring odd number of times in a Given array
Objective: Given an array of integers, in which every element occurs even a number of times except one number which occurs add a number of times. Find out that number.
Example:
int[] A = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7 }; Element appearing add number of times: 5
Approach:
we know that A XOR A = 0 so numbers appearing an even number of times will be canceled out and the remaining elements will be the number which is appearing an odd number of times.
Code:
Element appearing add number of times: 5
Also Read: