Skip to content

Commit f1796ba

Browse files
authored
Merge pull request #86 from Meuman/find_duplicate_number_python
Find duplicate number python
2 parents f08097f + e12b47d commit f1796ba

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

leetcode/java/linkedlist/2.java

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def findDuplicate(self, nums: List[int]) -> int:
3+
tortoise = nums[0]
4+
hare = nums[0]
5+
# do {
6+
# tortoise = nums[tortoise]
7+
# hare = nums[nums[hare]]
8+
# } while (tortoise != hare)
9+
while 1:
10+
tortoise = nums[tortoise]
11+
hare = nums[nums[hare]]
12+
if tortoise==hare:
13+
break
14+
ptr1 = nums[0]
15+
ptr2 = hare
16+
while (ptr1 != ptr2):
17+
ptr1 = nums[ptr1]
18+
ptr2 = nums[ptr2]
19+
return ptr1;

0 commit comments

Comments
 (0)