Skip to content

Commit 6d7271d

Browse files
Time: 11 ms (55.13%), Space: 75.8 MB (51.58%) - LeetHub
1 parent 6366b0f commit 6d7271d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int findDuplicate(int[] nums) {
3+
int tortoise=nums[0];
4+
int hare=nums[0];
5+
do{
6+
tortoise=nums[tortoise];
7+
hare=nums[nums[hare]];
8+
}while(tortoise!=hare);
9+
10+
tortoise=nums[0];
11+
12+
while(tortoise!=hare){
13+
tortoise=nums[tortoise];
14+
hare=nums[hare];
15+
}
16+
17+
return hare;
18+
}
19+
}

0 commit comments

Comments
 (0)