Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def findDuplicate(self, nums: List[int]) -> int:
- n=len(nums)
- s,f=nums[0],nums[nums[0]]
- while s!=f:
- s=nums[s]
- f=nums[nums[f]]
- #now make reset f to 0 and both s,f move only step. To meet the duplicate number
- f=0
- while s!=f:
- s,f=nums[s],nums[f]
- return s
Advertisement
Add Comment
Please, Sign In to add comment