python leetcode 287. Find the Duplicate Number

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]

猜你喜欢

转载自blog.csdn.net/Neekity/article/details/85135545