All problems

Find All Duplicates in an Array

Medium · hash map

A list nums holds n integers, and every integer is between 1 and n (inclusive). No value appears more than twice.

Return every value that appears exactly twice, in ascending order. If no value appears twice, return an empty list.

Examples

Example 1

Input: nums = [5, 1, 5, 3, 3, 6]

Output: [3, 5]

Both 3 and 5 appear twice. The other values appear once.

Example 2

Input: nums = [2, 1, 3]

Output: []

Every value appears once.

Example 3

Input: nums = [2, 2]

Output: [2]

Constraints