From 7c60dee83b436e8e8a667bf9f191beced8de4fc3 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Mon, 10 Mar 2025 00:36:13 -0600 Subject: chore: move cpp and rust code to directory --- other/group_anagrams.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 other/group_anagrams.cpp (limited to 'other/group_anagrams.cpp') diff --git a/other/group_anagrams.cpp b/other/group_anagrams.cpp new file mode 100644 index 0000000..a2a7c8a --- /dev/null +++ b/other/group_anagrams.cpp @@ -0,0 +1,18 @@ +#include "leetcode.h" + +class Solution { +public: + vvd(string) groupAnagrams(vector &strs) { + map, vector> groups; + for (string s : strs) { + array hash = {0}; + for (char c : s) + ++hash[c - 'a']; + groups[hash].push_back(s); + } + vvd(string) ans; + for (auto [hash, group] : groups) + ans.push_back(group); + return ans; + } +}; -- cgit v1.2.3