There are many numbers in an array and each number appears three times excepting for one special number appearing once. Here is the question: how can I find the special numb
A possible algorithm (very generic, not tested) :
function findMagicNumber(arr[0...n])
magic_n := NaN
if n = 1 then
magic_n := arr[0]
else if n > 1 then
quicksort(arr)
old_n := arr[0]
repeat := 0
for i := 1 to n
cur_n := arr[i]
repeat := repeat + 1
if cur_n ≠ old_n then
if repeat = 1 then
magic_n := old_n
old_n := cur_n
repeat := 0
return magic_n