public int findDuplicate(int[] nums) {
        int slow = 0, fast = 0;
        while (fast < nums.length && nums[fast] < nums.length) {
            slow = nums[slow];
            fast = nums[nums[fast]];
            if (slow == fast) break;
        }
        // can also identify if there's no cycle (duplicate)
        if (fast >= nums.length || nums[fast] >= nums.length) return -1;
        fast = 0;
        while (fast != slow) {
            slow = nums[slow];
            fast = nums[fast];
        }
        return fast;
    }