Last active
April 6, 2020 19:39
-
-
Save munguial/44f2de7c9a47d10ab1e0a383acc11bf8 to your computer and use it in GitHub Desktop.
Day 6 - Group anagrams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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