Skip to content

Instantly share code, notes, and snippets.

@ardenn
Created October 16, 2020 19:28
Show Gist options
  • Save ardenn/1ed83b2805a2f4c1d0a64dbda3b49f09 to your computer and use it in GitHub Desktop.
Save ardenn/1ed83b2805a2f4c1d0a64dbda3b49f09 to your computer and use it in GitHub Desktop.
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
@Eleazar-Harold
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment