#include #include #include #include class Solution { using words_t = std::vector; public: std::vector groupAnagrams(const words_t &strs) { std::unordered_map groups; for (const auto &s : strs) { std::string sorted_s = s; std::sort(sorted_s.begin(), sorted_s.end()); groups[sorted_s].push_back(s); } std::vector result; for (const auto [_, words] : groups) { result.push_back(std::move(words)); } return result; } };