본문 바로가기
코딩테스트

[ LeetCode ] 49번 Group Anagrams

by 코뮤(commu) 2021. 4. 19.
728x90
반응형

 

leetcode.com/problems/group-anagrams/

 

Group Anagrams - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

 

 

 

 

class Solution:
    def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
        ana = collections.defaultdict(list)
        
        for word in strs:
            ana[''.join(sorted(word))].append(word)
        
        return ana.values()

 

 

 

 

 

 

 

 

 

 

 

 

728x90
반응형