nums. Duplicates should be counted only once.Count Unique
L1 Easy Arrays & Hashing
Concept
Since a
Set keeps one copy of each distinct value, its count tells you how many unique numbers exist.Return how many distinct integers appear in
Examples
▸ nums = [1, 2, 3, 1, 2]
→ 3
▸ nums = []
→ 0
▸ nums = [7, 7, 7, 7]
→ 1
Progressive Hints
Hint 1 · Nudge
Duplicates should collapse into one. What collection does that for you automatically?
Hint 2 · Plan
Put every number into a set, which keeps just one copy of each value. Return the size of that set.
Hint 3 · Approach
Return the size of the set built from the array.
All hints are out. Take a breath and give it a shot.
Output
// Run your code to see the output here.