Skip to content

Instantly share code, notes, and snippets.

@prodeveloper
Created May 2, 2018 06:45
Show Gist options
  • Save prodeveloper/df28e29cfe434147eaefd3cc64047a64 to your computer and use it in GitHub Desktop.
Save prodeveloper/df28e29cfe434147eaefd3cc64047a64 to your computer and use it in GitHub Desktop.
Removing duplicates
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