From 22eaaba7d3e0fc634ad2a4d0fd0bf7478da5691a Mon Sep 17 00:00:00 2001 From: Sam2022moon <104721736+Sam2022moon@users.noreply.github.com> Date: Tue, 23 Apr 2024 04:15:06 +0900 Subject: [PATCH] 4th problem --- sam_lee/Group_Anagrams.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 sam_lee/Group_Anagrams.py diff --git a/sam_lee/Group_Anagrams.py b/sam_lee/Group_Anagrams.py new file mode 100644 index 000000000..cb9a3f7cb --- /dev/null +++ b/sam_lee/Group_Anagrams.py @@ -0,0 +1,12 @@ +from collections import defaultdict + +class Solution: + def groupAnagrams(self, strs: List[str]) -> List[List[str]]: + anagrams = defaultdict(list) + + for word in strs: + anagrams[str(sorted(word))].append(word) + + return anagrams.values() + + \ No newline at end of file