forked from Shubhamlmp/Programming-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_Distinct_Numbers.cpp
More file actions
47 lines (36 loc) · 764 Bytes
/
13_Distinct_Numbers.cpp
File metadata and controls
47 lines (36 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int solution()
{
int n, count=0;
//Taking input for number of elements in the array
cin>>n;
//Declaring an array of size n
int a[n];
//Taking n inputs for n no. of elements of the array
for(int i=0; i<n;i++)
{
cin>>a[i];
}
//Declaring a set which only stores distinct elements
unordered_set<int> s;
//Inserting element inside set only if element is already no present and storing its count
for(int i=0; i<n;i++)
{
if(s.find(a[i])==s.end())
{
s.insert(a[i]);
count++;
}
}
//Printing number of distinct elements present
cout << count;
return 0;
}
int main()
{
//Function call
solution();
return 0;
}