1. 程式人生 > >python leetcode 287. Find the Duplicate Number

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]