1 parent 046c4f5 commit ecfa02aCopy full SHA for ecfa02a
1 file changed
solutions/287. Find the Duplicate Number/AC_Floyd.java
@@ -0,0 +1,21 @@
1
+ /**
2
+ * 参考 Link list Cycle II
3
+ * Floyd 判圈法找环的起点
4
+ *
5
+ */
6
+public class Solution {
7
+ public int findDuplicate(int[] nums) {
8
+ int slow = 0, fast = 0;
9
+ do{
10
+ slow = nums[slow];
11
+ fast = nums[nums[fast]];
12
+ }while(slow != fast);
13
+
14
+ int find = 0;
15
+ while(find != slow){
16
+ find = nums[find];
17
18
+ }
19
+ return find;
20
21
+}
0 commit comments