Find the Duplicate Number (LC-0287)
class Solution:
def findDuplicate(self, nums):
fast = slow = nums[0]
started = True
while True:
if not started and slow == fast:
break
started = False
fast = nums[nums[fast]]
slow = nums[slow]
fast = nums[0]
while True:
if slow == fast:
break
fast = nums[fast]
slow = nums[slow]
return slow