LeetCode 49. Group Anagrams - Python

preview_player
Показать описание
Given an array of strings strs, group the anagrams together. You can return the answer in any order.

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Рекомендации по теме
Комментарии
Автор

great, simple explanation, much appreciated

athbuys
Автор

Your explanation is by far the easiest to understand.

thank you

mheyrie
Автор

Thank you so much! Your explanation was a lot more helpful than other videos :).

franzeugenio
Автор

Whats the Complexity of this solution?

ahmadmohamadi
Автор

class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:


d = {}

for words in strs:
key = tuple(sorted(words))

d[key] = d.get(key, []) + [words]

return d.values()

maged_helmy
join shbcf.ru