Does anyone have an idea why elements appear only once or twice? At least the common "mark by negating" solution also works when elements appear more often. Is there a better solution that takes advantage of the fact that elements don't appear more than twice?
Why only once or twice?


@StefanPochmann said in Why only once or twice?:
Does anyone have an idea why elements appear only once or twice? At least the common "mark by negating" solution also works when elements appear more often. Is there a better solution that takes advantage of the fact that elements don't appear more than twice?
but the time complexity of current solution is O(n) now. It seems impossible to reduce it.

I just posted a solution to make use of the fact that any element may at most repeat twice. Just for fun.
https://discuss.leetcode.com/topic/74787/pythonsolutionwithoutusingabs