Created
October 16, 2020 19:28
-
-
Save ardenn/1ed83b2805a2f4c1d0a64dbda3b49f09 to your computer and use it in GitHub Desktop.
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
def get_unique(m:list): | |
c = {} | |
for i in m: | |
if c.get(i) is not None: | |
c.pop(i) | |
c[i] = i | |
return next(iter(c.values())) | |
assert get_unique([6,1,3,3,3,6,6]) == 1 | |
assert get_unique([13,19,13,13]) == 19 | |
assert get_unique([1,2,3,4,5,1,2,3,4,1,2,3,4]) == 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this works it's O(1) space and O(M) time.
Try using the bitwise operators to achieve the O(1).
I did my logic in Golang. here's the link