Finding a number that repeats even no of times where all the other numbers repeat odd no of times

前端 未结 5 455
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-18 01:41

Given is an array of integers. Each number in the array repeats an ODD number of times, but only 1 number is repeated for an EVEN number of times. Find that number.

5条回答
  •  孤城傲影
    2020-12-18 02:16

    Apparently there is a solution in O(n) time and O(1) space, since it was asked at a software engineer company with this constraint explictly. See here : Bing interview question -- it seems to be doable using XOR over numbers in the array. Good luck ! :)

提交回复
热议问题