class Solution:
def findDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
for i in range(len(nums)):
index = abs(nums[i])-1
if nums[index] < 0:
return abs(nums[i])
else:
nums[index] = -nums[index]
python leetcode 287. Find the Duplicate Number
最新推荐文章于 2024-08-18 02:36:57 发布