Distinct Numbers
You are given a list of integers, and your task is to calculate the number of distinct values in the list.
Input
The first input line has an integer : the number of values.
The second line has integers .
Output
Print one integers: the number of distinct values.
Constraints
Input:
Output:
Input
The first input line has an integer : the number of values.
The second line has integers .
Output
Print one integers: the number of distinct values.
Constraints
Input:
5
2 3 2 2 3
Output:
2
void solve() {// n is the size of array
int n;cin>>n;// map to store the unique elements and its frequency
map<int,int>m;
for (int i = 0; i < n; i++){ int x; cin>>x; m[x]++;}// total unique elements is the size of the mapcout<<m.size()<<endl;
}
0 Comments
If you have any doubts/suggestion/any query or want to improve this article, you can comment down below and let me know. Will reply to you soon.