Lonely Integer

  • + 0 comments

    It's rare to see, but Python has its own XOR operator!

    Just be aware that the following code does not works if the array has an element with more than two occurrences:

    def lonelyinteger(a):
        unique = 0
        for num in a:
            unique ^= num
        return unique