Skip to content

Commit f2da16a

Browse files
authored
Create 287-Find-The-Duplicate-Number.py
1 parent a1eb219 commit f2da16a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

287-Find-The-Duplicate-Number.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def findDuplicate(self, nums: List[int]) -> int:
3+
slow, fast = 0, 0
4+
while True:
5+
slow = nums[slow]
6+
fast = nums[nums[fast]]
7+
if slow == fast:
8+
break
9+
10+
slow2 = 0
11+
while True:
12+
slow = nums[slow]
13+
slow2 = nums[slow2]
14+
if slow == slow2:
15+
return slow

0 commit comments

Comments
 (0)