Skip to content

Group anagrams · ⁨变位词分组⁩

English

Group anagrams

Two words are anagrams if they use exactly the same letters, like eat and tea. Group the anagrams together and return a list of groups.

The trick: sort the letters of each word to make a key — eat and tea both become aet. Words with the same key belong in the same group. Use a dictionary from key → list of words, and remember the order the keys first appear.

中文

变位词分组

如果两个单词使用的字母完全相同,它们就是变位词,比如 eat 和 tea。把变位词分到一组,并返回分组列表。

技巧:把每个单词的字母排序,作为键 —— eat 和 tea 都变成 aet。键相同的单词属于同一组。用一个从「键 → 单词列表」的字典,并记住键首次出现的顺序。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩