class Solution:
    def get_duplicate(self, nums):
        if not nums:
            return
        
        slow = nums[0]
        fast = nums[slow] # which is nums[nums[0]]
        while slow != fast:
            slow = nums[slow]
            fast = nums[nums[fast]]
        
        fast = 0
        while slow != fast:
            slow = nums[slow]
            fast = nums[fast]
        
        return fast

nums = [1, 3, 2, 4, 3]
solution = Solution()
print(solution.get_duplicate(nums))