You have N integers. Every integer repeats itself even number of times except one. Find that one.
#include <iostream>
using namespace std;
int main()
{
int arr[11] = {1,2,1,3,2,4,5,5,4,3,6};
int result=0;
for(int i=0; i<11; i++)
{
result^=arr[i];
}
cout <<result;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int arr[11] = {1,2,1,3,2,4,5,5,4,3,6};
int result=0;
for(int i=0; i<11; i++)
{
result^=arr[i];
}
cout <<result;
return 0;
}
haha.......sahi hai beedu
ReplyDeletebut sometimes you should think of more than one solution...hash table and sorting is not a bad idea either
ReplyDelete