Solved: 25 - Container Adapters
This commit is contained in:
@@ -1,20 +1,55 @@
|
||||
#include "container_adapters.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
namespace stl_containers {
|
||||
|
||||
auto is_balanced_parentheses(const std::string& text) -> bool {
|
||||
(void)text;
|
||||
std::stack<char> s;
|
||||
for (const auto c: text) {
|
||||
switch (c) {
|
||||
case '(':
|
||||
s.push(')');
|
||||
break;
|
||||
case '[':
|
||||
s.push(']');
|
||||
break;
|
||||
case '{':
|
||||
s.push('}');
|
||||
break;
|
||||
case ')':
|
||||
case ']':
|
||||
case '}': {
|
||||
if (const auto n = s.top(); c != n) return false;
|
||||
s.pop();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (s.empty()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto simulate_queue(const std::vector<int>& arrivals) -> std::vector<int> {
|
||||
(void)arrivals;
|
||||
return {};
|
||||
auto v = std::vector<int>{};
|
||||
const auto push = [&v](const int val){v.push_back(val);};
|
||||
std::ranges::for_each(arrivals, push);
|
||||
return v;
|
||||
}
|
||||
|
||||
auto top_k_largest(const std::vector<int>& data, int k) -> std::vector<int> {
|
||||
(void)data; (void)k;
|
||||
return {};
|
||||
auto top_k_largest(const std::vector<int>& data, const int k) -> std::vector<int> {;
|
||||
auto v = std::vector<int>{};
|
||||
std::ranges::for_each(data, [&v](const auto& p){v.push_back(p);});
|
||||
// Remove duplicates
|
||||
std::set<int> s{v.begin(), v.end()};
|
||||
v = std::vector<int>{s.begin(), s.end()};
|
||||
std::ranges::sort(v, std::ranges::greater{});
|
||||
v.resize(k);
|
||||
return v;
|
||||
}
|
||||
|
||||
} // namespace stl_containers
|
||||
|
||||
Reference in New Issue
Block a user