How to find the only number in an array that doesn't occur twice [duplicate]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: find the only unpaired element in the array 7 answers The following is taken from a job interview: In a given array, which contains integers, each number repeats itself once except for one, which doesn't repeat. Write a function that finds the number that doesn't repeat. I thought about using an HashSet, but it might complicate everything... Any ideas of a simple solution? 回答1: You can define an integer "result" initialized to 0, and then you do some bitwise operations by applying a XOR logic to all