-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path287.py
31 lines (28 loc) · 862 Bytes
/
287.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#==================================================
#==> Title: find-the-duplicate-number
#==> Author: Zhang zhen
#==> Email: hustmatnoble.gmail.com
#==> GitHub: https://github.com/MatNoble
#==> Date: 1/14/2021
#==================================================
"""
https://leetcode-cn.com/problems/find-the-duplicate-number/
"""
class Solution:
def findDuplicate(self, nums):
slow, fast = 0, 0
while True:
slow = nums[slow]
fast = nums[nums[fast]]
if slow == fast:
break
find = 0
while True:
find = nums[find]
slow = nums[slow]
if slow == find:
break
return slow
nums = [2, 3, 1, 5, 1, 4]
mat = Solution()
mat.findDuplicate(nums)