题目:
题解:
class Solution:
def findDuplicate(self, nums: List[int]) -> int:
n = len(nums)
l, r = 1, n - 1
ans = -1
while l <= r:
mid = (l + r) // 2
cnt = sum(1 for num in nums if num <= mid)
if cnt <= mid:
l = mid + 1
else:
r = mid - 1
ans = mid
return ans