#111Easy
Number of distinct elements
Time: 1 s · Memory: 256 MB
- Maps and sets
Statement
You are given an array of numbers. Find how many distinct numbers it contains.
Input format
The first line contains (). The second line contains integers ().
Output format
A single integer — the number of distinct values.
Examples
Input
6 5 1 2 4 3 1
Output
5
Input
3 7 7 7
Output
1
Note
A set stores every value only once: adding the same value again changes nothing. Put all numbers into a set — the answer is its size. Python — set, C++ — set / unordered_set, Go — map[int64]bool.
For comparing every element with all others ( operations) is too slow — a set or a dictionary does it in one pass.
