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

前端 未结 5 452
爱一瞬间的悲伤
爱一瞬间的悲伤 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:07

    I don't know what the intended meaning of "repeat" is, but if there is an even number of occurrences of (all-1) numbers, and an odd number of occurances for only one number, then XOR should do the trick.

提交回复
热议问题