Skip to content

Instantly share code, notes, and snippets.

@munguial
Last active April 6, 2020 19:39
Show Gist options
  • Save munguial/44f2de7c9a47d10ab1e0a383acc11bf8 to your computer and use it in GitHub Desktop.
Save munguial/44f2de7c9a47d10ab1e0a383acc11bf8 to your computer and use it in GitHub Desktop.
Day 6 - Group anagrams
# https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3288/
from collections import defaultdict
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
anagrams = defaultdict(list)
for s in strs:
anagrams[str(sorted(s))].append(s)
return anagrams.values()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment