Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

Single Number

B

what an amazing solution

S

Kudos, quite a nice work!

N

yes, XOR is commutative so N1^N2^N3 = N1^N3^N2=N2^N3^N1=N2^N1^N3=......

A

But then you are using extra memory ;)

the first solution could be optimized like:

How can this be done in python, this code malfunctions for [1,0,1] test case in python.

H

If take "i" as consider, this is no extra space :)

@marrvolo The XOR operation is one single machine operation, it doesn't matter the length of binary number.

Also, in Big O(), O(n) is equivalent as O(x*n), the complexity remains linear which is what we care most of the time.

No one has replied

L

this is so coooool!

Z

greet solution

Brilliant!!! But who can tell me the space complexity of the code? Thx!

C

I think your code works now on the current judge system~

excellent. two xor operations cancel each other.

This will be valuable as functional programming languages becoming increasing popular in the job marketing.

@monil1511gmail.com When do the XOR operation between same numbers, the result is 0. For example, "1101" XOR "1101", the result is "0000". Then in this problem, the paired values are eliminated by XOR, and the single value will be left.

R

Hi @MissMary , I did a small modification which based on your code

import operator return reduce(operator.xor,num)

Disabled Categories are greyed out

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.