Skip to content

Commit

Permalink
Added Solution of 1st problem of DAY22 in C++; Updated README (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
Razdeep committed Jan 18, 2019
1 parent fe960d5 commit 898a228
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
23 changes: 23 additions & 0 deletions day22/C++/commonElements.cpp
@@ -0,0 +1,23 @@
/**
* @author: Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com>
* @github: https://github.com/razdeep
* @date: 18/01/2019
*/
#include <bits/stdc++.h>

int main()
{
std::vector<int> a = {1, 2, 3, 4, 5, 6, 8, 8, 7};
std::vector<int> b = {4, 2, 9, 1, 8};
std::sort(a.begin(), a.end());
auto last_ptr = std::unique(a.begin(), a.end());
a.resize(std::distance(a.begin(), last_ptr));

for (auto i : a)
{
if (std::find(b.begin(), b.end(), i) != b.end())
std::cout << i << std::endl;
}

return 0;
}
27 changes: 27 additions & 0 deletions day22/README.md
Expand Up @@ -158,7 +158,34 @@ console.log (searchCommonElements ([0, 12, 41, 20], [9, 3, 1, 5]));
```

***
## C++ Implementation

### [Solution 1](./C++/commonElements.cpp)
```cpp
/**
* @author: Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com>
* @github: https://github.com/razdeep
* @date: 18/01/2019
*/
#include <bits/stdc++.h>

int main()
{
std::vector<int> a = {1, 2, 3, 4, 5, 6, 8, 8, 7};
std::vector<int> b = {4, 2, 9, 1, 8};
std::sort(a.begin(), a.end());
auto last_ptr = std::unique(a.begin(), a.end());
a.resize(std::distance(a.begin(), last_ptr));

for (auto i : a)
{
if (std::find(b.begin(), b.end(), i) != b.end())
std::cout << i << std::endl;
}

return 0;
}
```
## Question 2

## JavaScript Implementation
Expand Down

0 comments on commit 898a228

Please sign in to comment.