Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Distinct_Numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#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;
}