Skip to content

Commit 898a228

Browse files
authored
Added Solution of 1st problem of DAY22 in C++; Updated README (#188)
1 parent fe960d5 commit 898a228

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

day22/C++/commonElements.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @author: Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com>
3+
* @github: https://github.com/razdeep
4+
* @date: 18/01/2019
5+
*/
6+
#include <bits/stdc++.h>
7+
8+
int main()
9+
{
10+
std::vector<int> a = {1, 2, 3, 4, 5, 6, 8, 8, 7};
11+
std::vector<int> b = {4, 2, 9, 1, 8};
12+
std::sort(a.begin(), a.end());
13+
auto last_ptr = std::unique(a.begin(), a.end());
14+
a.resize(std::distance(a.begin(), last_ptr));
15+
16+
for (auto i : a)
17+
{
18+
if (std::find(b.begin(), b.end(), i) != b.end())
19+
std::cout << i << std::endl;
20+
}
21+
22+
return 0;
23+
}

day22/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,34 @@ console.log (searchCommonElements ([0, 12, 41, 20], [9, 3, 1, 5]));
158158
```
159159

160160
***
161+
## C++ Implementation
161162

163+
### [Solution 1](./C++/commonElements.cpp)
164+
```cpp
165+
/**
166+
* @author: Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com>
167+
* @github: https://github.com/razdeep
168+
* @date: 18/01/2019
169+
*/
170+
#include <bits/stdc++.h>
171+
172+
int main()
173+
{
174+
std::vector<int> a = {1, 2, 3, 4, 5, 6, 8, 8, 7};
175+
std::vector<int> b = {4, 2, 9, 1, 8};
176+
std::sort(a.begin(), a.end());
177+
auto last_ptr = std::unique(a.begin(), a.end());
178+
a.resize(std::distance(a.begin(), last_ptr));
179+
180+
for (auto i : a)
181+
{
182+
if (std::find(b.begin(), b.end(), i) != b.end())
183+
std::cout << i << std::endl;
184+
}
185+
186+
return 0;
187+
}
188+
```
162189
## Question 2
163190

164191
## JavaScript Implementation

0 commit comments

Comments
 (0)