Skip to content

Commit 184d97f

Browse files
authored
Merge pull request #16 from Sam-bhav-20/main
issue resolved of removing duplicates from an array
2 parents 6c54e53 + 33b8210 commit 184d97f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define int long long
4+
#define MOD 1e9 + 7
5+
const long long N=10000005;
6+
7+
8+
main()
9+
{
10+
//Declare an array size;
11+
int n;
12+
cout<<"Size of an array: ";
13+
cin>>n;
14+
15+
//declare a set also as inserting into sets as it will remove the duplicates
16+
17+
//declare an array of size n
18+
19+
int a[n];
20+
21+
//unordered set for better time complexity
22+
unordered_set<int> sam;
23+
cout<<"Elements of an array: ";
24+
for(int i=0;i<n;i++)
25+
{
26+
cin>>a[i];
27+
sam.insert(a[i]);
28+
}
29+
30+
cout<<"Array without duplicates: ";
31+
32+
for(int it:sam)
33+
{
34+
cout<<it<<" ";
35+
}
36+
cout<<endl;
37+
}

0 commit comments

Comments
 (0)