Find the Number Occurring Odd Number of Times

0



 You are given an array . In this array there are numbers repeated some are repeated for even number of times and some of them are repeated for odd number of times. In this you have to find out the number which is repeated odd number of times.


Example :

Input :

arr[] = [1,1,2,2,1,2,2]

Output :

1




class HindiCodingCommunity{
public static int odd(int arr[],int n)
{
int val= 0;
for(int i=0;i<n;i++)
{
val= val^arr[i];
}
return val;
}
public static void main(String args[])
{
int arr[] = {4 ,4 ,5 ,5 ,4 ,4 ,4 ,5 ,5 };
int n = 9;
System.out.println(odd(arr, n));


}
}

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !