Skip to content

Instantly share code, notes, and snippets.

@repen
Last active May 5, 2019 19:23
Show Gist options
  • Save repen/681bf1905c761eeca683ced85bbe6789 to your computer and use it in GitHub Desktop.
Save repen/681bf1905c761eeca683ced85bbe6789 to your computer and use it in GitHub Desktop.
Search dublicate
arr = [1,2,1,5,2,1,3,2,4]
# arr = [1,2,3,4]
class MyException(ValueError):
pass
def dublicate(arr, repeat = []):
if not arr:
raise MyException("Exception None dublicate")
elif arr[0] in repeat:
return arr[0]
else:
if arr.count(arr[0]) >= 2:
repeat.append(arr[0])
return dublicate(arr[1:])
res = dublicate(arr)
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment