Using XOR operator for finding duplicate elements in a array fails in many cases

前端 未结 6 2067
野的像风
野的像风 2021-02-01 10:36

I came across a post How to find a duplicate element in an array of shuffled consecutive integers? but later realized that this fails for many input.

For ex:
a

6条回答
  •  青春惊慌失措
    2021-02-01 11:13

    Although the answers provided here are good, yet I'd like you to refer the answer by Mohit Jain if there is an ambiguity.

    The fact variable xor variable = zero can be used to locate the duplicates present in the array precisely and easily. Hope that helps!

提交回复
热议问题