The head of this list is 0, I think this one is easier to understand:

class Solution { public: int findDuplicate(vector<int>& nums) { if(nums.empty())return 0; int slow = 0,fast = 0; while(slow!=fast||slow==0) { slow = nums[slow]; fast = nums[nums[fast]]; } slow = 0; while(slow!=fast) { slow = nums[slow]; fast = nums[fast]; } return fast; } };Both the slow node and the fast node start from 0.