Created
December 15, 2019 17:51
-
-
Save lion137/37db480d8c291744a24d22d680553e91 to your computer and use it in GitHub Desktop.
xor to find unpaired
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python: | |
def find_unpaired(xs): | |
"""find unpaired element with array of 2n + 1 elements""" | |
for i in range(1, len(xs)): | |
xs[i] ^= xs[i - 1] | |
print(xs[len(xs) - 1]) | |
# pseudocode: | |
fun findUnpaired(aList): | |
#N - length of input list | |
for i from 1 to N: | |
aList[i] ^= aList[i - 1] | |
print(aList[N - 1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment