03. offer wins the array face questions duplicate numbers

Find an array duplicate numbers.


All numbers in an array of length nums n's are in the range of 0 ~ n-1. Some digital array is duplicated, but do not know how many numbers repeat, do not know each number was repeated several times. Please find an array of any one of the duplicate numbers.

Example 1:

Input:
[2, 3, 1, 0, 2, 5, 3]
Output: 2 or 3 
 

limit:

2 <= n <= 100000

 

class Solution:
    def findRepeatNumber(self, nums: List[int]) -> int:
        a = nums.sort()
        before = nums[0]
        for i in range (1,len(nums)):
            if before == nums[i]:
                return before
            before = nums[i]

 

Published 413 original articles · won praise 242 · views 540 000 +

Guess you like

Origin blog.csdn.net/qq_32146369/article/details/104909377