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