Here is the C# code with HashTable
class Class1
{
public int Different_Number(int[] A, int[] B)
{
if (A.Length < B.Length)
{
return Hash_It(A, B);
}
else
{
return Hash_It(B, A);
}
}
private int Hash_It(int[] A, int[] B)
{
Hashtable ht = new Hashtable();
for (int i = 0; i < A.Length; i++)
{
ht.Add(A[i], i);
}
for (int i = 0; i < B.Length; i++)
{
if (!ht.Contains(B[i]))
{
return B[i];
}
}
return null;
}
public static void Main()
{
int[] A = new int[] { 1,5,3,8}; /* Unsorted array */
int[] B = new int[] { 5,3,8,2102,1};
Class1 cls = new Class1();
Console.WriteLine(cls.Different_Number(A, B));
Console.ReadLine();
}
}