We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 6c54e53 + 33b8210 commit 184d97fCopy full SHA for 184d97f
removingDuplicates/removeDupFromArray.cpp
@@ -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