Missing Number


regarding Approach #3, I believe this will only work if:
index 0 and num 0,
index 1 has num 1,
index 5 has num 5,
index 9 has num 9
etc...what if index 0 has 251
index 1 has 267
index 2 has 305
etc???@jjsomiya  what do you think ?

@seakhar The numbers do not have to be in order because XOR is a commutative function.
However, your second example does not fit the constraints of the problem (unless the array is at least 305 elements long). See: "n distinct numbers taken from 0, 1, 2, ..., n"

private int[] Sortarray(int[] array)
{
for(int x = 0; x < array.Length; x++)
{
for(int y = x; y < array.Length; y++)
{
if(array[y] < array[x])
{
int a = array[x];
array[x] = array[y];
array[y] = a;
}
}
}
return array;
}public int FindMissingNumber(int[] array) { int value = 0; array = (Sortarray(array)); for(int x = 0; x < array.Length; x++) { if(x < array.Length) { if(array[x + 1] == array[x] + 1) { continue; } else { value = array[x] + 1; x = array.Length; } } } return value; }