diff --git a/challenges/firstDuplicate/firstDuplicate.py b/challenges/firstDuplicate/firstDuplicate.py new file mode 100644 index 0000000..1b84a21 --- /dev/null +++ b/challenges/firstDuplicate/firstDuplicate.py @@ -0,0 +1,11 @@ +def firstDuplicate(a): + seen = set() + for num in a: + if num in seen: + return num + seen.add(num) + return -1 + +assert firstDuplicate([2, 1, 3, 5, 3, 2]) == 3 +assert firstDuplicate([2, 2]) == 2 +assert firstDuplicate([2, 4, 3, 5, 1]) == -1