class Solution:
def findDuplicate(self, nums: List[int]) -> int:
# method 1
# flags = [True]*(len(nums))
# for val in nums:
# if flags[val-1]:
# flags[val-1] = False
# else:
# return val
# method 2
# temp = sorted(nums)
# for i in range(1, len(temp)):
# if temp[i] == temp[i-1]:
# return temp[i]
# method 3
# counts = [0]*len(nums)
# for val in nums:
# counts[val-1] += 1
# if counts[val-1]>1:
# return val
# # method 4
# def count_le(left, mid):
# res = 0
# for val in nums:
# if left<= val <= mid:
# res += 1
# return res
# left, right = 1, len(nums)
# while left < right:
# mid = left+(right-left)//2
# if count_le(left, mid) <= mid-left+1:
# left = mid + 1
# else:
# right = mid
# return left
来源:CSDN
作者:呆坐的熊
链接:https://blog.csdn.net/Lin_RD/article/details/104750150