We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 719e10e commit 0fc29b1Copy full SHA for 0fc29b1
287-find-the-duplicate-number.js
@@ -1,3 +1,28 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {number}
4
+ */
5
+const findDuplicate = function(nums) {
6
+ const len = nums.length
7
+ if(len > 0) {
8
+ let slow = nums[0]
9
+ let fast = nums[nums[0]]
10
+ while(slow !== fast) {
11
+ slow = nums[slow]
12
+ fast = nums[nums[fast]]
13
+ }
14
+ slow = 0
15
16
17
+ fast = nums[fast]
18
19
+ return slow
20
21
+ return -1;
22
+};
23
+
24
+// another
25
26
/**
27
* @param {number[]} nums
28
* @return {number}
0 commit comments