Find Duplicate Numbers in a List
0:00:00
Given a list of integers, identify all the duplicate values in the list. Assume that the list can contain both positive and negative numbers, and the order of the list does not matter. A number is considered a duplicate if it appears more than once in the list. Return a list of the duplicate numbers.
Example 1:
Input:
nums = [1, 2, 3, 1, 2, 3]
Output:
find_duplicates(nums) -> [1, 2, 3]
The numbers 1, 2, and 3 all appear more than once in the list, so they are considered duplicates.
Example 2:
Input:
nums = [1, -1, 2, 3, 3, -1]
Output:
find_duplicates(nums) -> [-1, 3]
The numbers -1 and 3 both appear more than once in the list, so they are considered duplicates. Note that the order of the output does not matter.
Example 3:
Input:
nums = [1, 2, 3, 4, 5]
Output:
find_duplicates(nums) -> []
None of the numbers in the list appear more than once, so there are no duplicates.
Personalized based on your user activity, skill level, and preferences.
.
.
.
.
Comments