Skip to content

Instantly share code, notes, and snippets.

@kyrylomyr
Last active November 26, 2019 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyrylomyr/be6d03bbb58516ab3f87f89aa0be6176 to your computer and use it in GitHub Desktop.
Save kyrylomyr/be6d03bbb58516ab3f87f89aa0be6176 to your computer and use it in GitHub Desktop.
public class Solution
{
public int FindDuplicate(int[] nums)
{
var i1 = nums[0];
var i2 = nums[0];
do
{
i1 = nums[i1];
i2 = nums[nums[i2]];
}
while (i1 != i2);
i2 = nums[0];
while (i1 != i2)
{
i1 = nums[i1];
i2 = nums[i2];
}
return i1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment