<reponame>helderthh/leetcode
# 287. Find the Duplicate Number
# https://leetcode.com/problems/find-the-duplicate-number/


class Solution:
    def findDuplicate(self, nums: List[int]) -> int:
        
        
        # start hopping from Node_#0
        slow, fast = 0, 0
		
		# for locating start node of cycle
        check = 0
        
		# Step_#1
		# Cycle detection
        # Let slow jumper and fast jumper meet somewhere in the cycle 
		
        while True:
			# slow jumper hops 1 step, while fast jumper hops two steps forward.
            slow = nums[ slow ]
            fast = nums[ nums[fast] ]
            
            if slow == fast:
                break
        
        while True:
			# slow jumper hops 1 step, while fast jumper hops two steps forward.
            slow = nums[ slow ]
            check = nums[check]
            
            if slow == check:
                break
        return check
# 287. Find the Duplicate Number
# https://leetcode.com/problems/find-the-duplicate-number/


class Solution:
    def findDuplicate(self, nums: List[int]) -> int:
        
        
        # start hopping from Node_#0
        slow, fast = 0, 0
		
		# for locating start node of cycle
        check = 0
        
		# Step_#1
		# Cycle detection
        # Let slow jumper and fast jumper meet somewhere in the cycle 
		
        while True:
			# slow jumper hops 1 step, while fast jumper hops two steps forward.
            slow = nums[ slow ]
            fast = nums[ nums[fast] ]
            
            if slow == fast:
                break
        
        while True:
			# slow jumper hops 1 step, while fast jumper hops two steps forward.
            slow = nums[ slow ]
            check = nums[check]
            
            if slow == check:
                break
        return check
# 287. Find the Duplicate Number # https://leetcode.com/problems/find-the-duplicate-number/ # start hopping from Node_#0 # for locating start node of cycle # Step_#1 # Cycle detection # Let slow jumper and fast jumper meet somewhere in the cycle # slow jumper hops 1 step, while fast jumper hops two steps forward. # slow jumper hops 1 step, while fast jumper hops two steps forward.