프로그래밍/LeetCode
[LeetCode][Python3] 287. Find the Duplicate Number
snoopybox
2019. 1. 25. 00:06
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 :