Find a special number in an array

后端 未结 9 1670
天命终不由人
天命终不由人 2020-12-25 09:07

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

9条回答
  •  一个人的身影
    2020-12-25 09:58

    Since nobody's saying it, I will: hashtable.

    You can calculate how many times each element occurs in the array in O(n) with simple hashtable (or hashmap).

提交回复
热议问题