```
public class Solution
{
public int FindDuplicate(int[] nums)
{
int index1 = 0;
int index2 = 0;
while(true)
{
index2 = nums[index1];
if (index2 == -1)
return index1;
nums[index1] = -1;
index1 = index2;
}
return -1;
}
}```
```