Created
May 2, 2018 06:45
-
-
Save prodeveloper/df28e29cfe434147eaefd3cc64047a64 to your computer and use it in GitHub Desktop.
Removing duplicates
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 answer(numbers): | |
seen = set() | |
counter = 0 | |
zero_counter=0 | |
unique = [] | |
duplicate_value=None | |
numbers.insert(0,0) | |
for x in numbers: | |
if x in seen: | |
duplicate_value = x | |
break | |
seen.add(x) | |
unique.insert(counter,x) | |
counter+=1 | |
if numbers[-1]!=0 and duplicate_value is None: | |
return 0 | |
if numbers[-1]==0 and duplicate_value is None: | |
return len(numbers) | |
elif counter ==len(numbers): | |
return 0 | |
start_loop=unique.index(duplicate_value) | |
if duplicate_value == 0: | |
start_loop+=1 | |
return counter-start_loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment