So for example, the answer for the array:
1, 11, 3, 95, 23, 8, 1
would be 1, since all the other elements only occur once while 1 occurs twice.
A lot of the questions similar to this question that I've seen on stackoverflow ask to find the absolute majority (the answer occurs at least n/2 in an array of length n), or answer the question using sorting or a hash table. The former is not what I'm asking, and the latter is either too slow ( O(n log n) for sorting ) or uses too much memory ( O(n) for a hash table ).
Does such an algorithm exist? If not, is there a proof showing why it's impossible? Including a source would be nice.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…