Skip to content

Commit 61e70a5

Browse files
authored
add 287-Find-the-Duplicate-Number
1 parent 9b78240 commit 61e70a5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function findDuplicate(nums) {
2+
let slow = 0;
3+
let fast = 0;
4+
5+
while (true) {
6+
slow = nums[slow];
7+
fast = nums[nums[fast]];
8+
if (slow == fast) {
9+
break;
10+
}
11+
}
12+
13+
let slow2 = 0;
14+
15+
while (true) {
16+
slow = nums[slow];
17+
slow2 = nums[slow2];
18+
if (slow == slow2) {
19+
break;
20+
}
21+
}
22+
23+
return slow;
24+
}

0 commit comments

Comments
 (0)