Problem :

https://leetcode.com/problems/find-the-duplicate-number/


My Solution :

class Solution:
def findDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
slow = fast = nums[0]
while True:
slow = nums[slow]
fast = nums[nums[fast]]
if slow == fast:
slow = nums[0]
while slow != fast:
slow = nums[slow]
fast = nums[fast]
return slow


Comment :

https://en.wikipedia.org/wiki/Cycle_detection