Solved: 27 - Unordered Containers
This commit is contained in:
@@ -1,21 +1,37 @@
|
||||
#include "unordered_containers.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
|
||||
namespace stl_containers {
|
||||
|
||||
auto first_unique(const std::vector<std::string>& words) -> std::string {
|
||||
(void)words;
|
||||
return {};
|
||||
auto s = std::set<std::string>();
|
||||
for (const auto& word : words) {
|
||||
if (!s.contains(word)) {
|
||||
s.insert(word);
|
||||
} else {
|
||||
s.erase(word);
|
||||
}
|
||||
}
|
||||
return s.empty() ? "" : *s.begin();
|
||||
}
|
||||
|
||||
auto group_anagrams(const std::vector<std::string>& words)
|
||||
-> std::unordered_map<std::string, std::vector<std::string>> {
|
||||
(void)words;
|
||||
return {};
|
||||
auto groups = std::unordered_map<std::string, std::vector<std::string>>();
|
||||
for (const auto& word : words) {
|
||||
auto key = word;
|
||||
std::ranges::sort(key);
|
||||
groups[key].push_back(word);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
auto has_duplicate(const std::vector<int>& data) -> bool {
|
||||
(void)data;
|
||||
return false;
|
||||
auto s = std::set<int>{};
|
||||
for (auto i : data) s.insert(i);
|
||||
return s.size() != data.size();
|
||||
}
|
||||
|
||||
} // namespace stl_containers
|
||||
|
||||
Reference in New Issue
Block a user