Last active
December 17, 2015 19:29
-
-
Save st0le/5660547 to your computer and use it in GitHub Desktop.
2 Missing Duplicate
This file contains 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
import random | |
r = {random.randint(10,100) for i in xrange(10)} | |
lst = random.sample(r,len(r)) | |
l = lst[:2] + lst[2:] * 2 | |
random.shuffle(l) | |
def missing_2_numbers(lst): | |
xor = reduce(lambda a,b : a ^ b, lst) | |
mask = (xor & -xor) #get the right most set bit. | |
xor_1 = 0 | |
for v in lst: | |
if v & mask: | |
xor_1 = xor_1 ^ v | |
return (xor_1,xor ^ xor_1) | |
print l | |
print missing_2_numbers(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment