Deduplicate Preserving Order
EasyData EngineeringHash TableArraySorting
Description
Given an array nums, return a new array with duplicates removed, keeping the first occurrence of each value in its original order.
Examples
Input:
nums = [1,2,2,3,1]Output:
[1,2,3]Explanation:
Keeping only the first occurrence of each value yields [1,2,3].
Input:
nums = [5,5,5]Output:
[5]Explanation:
Keeping only the first occurrence of each value yields [5].
Input:
nums = [1,2,3]Output:
[1,2,3]Explanation:
Keeping only the first occurrence of each value yields [1,2,3].
Constraints
- •
1 ≤ nums.length ≤ 10⁴