Skip to content

Commit 0c9cfd3

Browse files
authored
Create firstDuplicate.py
1 parent b072099 commit 0c9cfd3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
#my first solution
3+
def firstDuplicate(a):
4+
d= {}
5+
for s in a:
6+
if s not in d:
7+
d[s]=1
8+
else:
9+
return s
10+
return -1
11+
12+
def firstDuplicate(a):
13+
mySet=set()
14+
for el in a:
15+
if el in mySet:
16+
return el
17+
mySet.add(el)
18+
return -1
19+
20+
def firstDuplicate(a):
21+
for i in a:
22+
a[abs(i)-1] *= -1
23+
if a[abs(i)-1] > 0:
24+
return abs(i)
25+
return -1

0 commit comments

Comments
 (0)