1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/cs/find-the-duplicate-number.cs
Matej Focko a56a328d6b
cs: add «287. Find the Duplicate Number»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-03-24 10:59:12 +01:00

19 lines
395 B
C#

public class Solution {
public int FindDuplicate(int[] nums) {
int slow = nums[0];
int fast = nums[0];
do {
slow = nums[slow];
fast = nums[nums[fast]];
} while (fast != slow);
slow = nums[0];
while (slow != fast) {
slow = nums[slow];
fast = nums[fast];
}
return slow;
}
}