Last active
November 26, 2019 08:30
-
-
Save kyrylomyr/be6d03bbb58516ab3f87f89aa0be6176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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