Skip to content

Latest commit

 

History

History

05_cyclicSort

Find all Duplicate Numbers

Given an unsorted array,nums, containing n numbers (from 1 to n).

find all of the duplicate numbers.

  • nums = [3, 4, 4, 5, 5]
  • output : [4, 5]

Task: With cyclic sort pattern, find all duplicate numbers in the given list.

Exercise: duplicateNumbers.py

Time complexity: O(n), N as the size of nums and the swap times

Space complexity: O(1), in constant space

Constraints:

  • 1 <= nums.length <= 1000
  • 1 <= nums[i] <= nums.length

《BACK》