The title

Find duplicate numbers in the array.

All numbers in an array of length n, nums, are in the range 0 to n-1. Some of the numbers in the array are repeated, but it is not known how many of them are repeated or how many times each number is repeated. Please find any duplicate number in the array.

Example 1: Input: [2, 3, 1, 0, 2, 5, 3] Output: 2 or 3Copy the code

Limitations:

2 <= n <= 100000

Their thinking

class Solution {
    func findRepeatNumber(_ nums: [Int]) -> Int {
//        var index : Int = 0
        var varNums = nums
        varNums.sort(by: {$0 < $1})
        for (index, value) in varNums.enumerated() {
            if index > 0 && varNums[index] == varNums[index-1] {
//                print("res:\(varNums[index])")
                return varNums[index]
            }
        }
        print("res:\(varNums)")
        return varNums[0]
    }
}
Copy the code