Given an array of numbers, except for one number all the
others occur twice. Give an algorithm to find that number
which occurs only once in the array.
Answer Posted / deepak
/*
you can also do some pre tests like array length should be odd.
just take an XOR of all the numbers it will give u the
number that occured single time.
it assumes that data is in correct form i.e. there is one
and only one number that occurs once.
*/
public static int whoOccursSingleTime(int a[]){
int s=0;
for(int i=0;i<a.length;i++){
s=s^a[i];
}
return s;
}
| Is This Answer Correct ? | 19 Yes | 3 No |
Post New Answer View All Answers
How can I do serial ("comm") port I/O?
What is #define size in c?
What is hashing in c language?
Is c procedural or object oriented?
Why are all header files not declared in every c program?
State the difference between realloc and free.
#include
Explain the use of #pragma exit?
What are the valid places to have keyword “break”?
Explain the properties of union.
In a byte, what is the maximum decimal number that you can accommodate?
Can you tell me how to check whether a linked list is circular?
What is the difference between break and continue?
How do you view the path?
why wipro wase