Skip to content
Onsite

Find Duplicates in Array

EasyP2Coding

Given an array of integers nums, return every value that appears at least twice, each listed once, in increasing order. Return an empty array if there are no duplicates.

Example 1

Input
nums = [4,3,2,7,8,2,3,1]
Output
[2,3]
Why
2 and 3 each appear twice.

Example 2

Input
nums = [1,1,2]
Output
[1]

Example 3

Input
nums = [1]
Output
[]

Constraints

  • 0 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9

Hints

Run checks the 3 visible tests, Submit all 10.