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.

日本語

アナグラムをグループ化

2つの単語がアナグラムとは、同じ文字をちょうど使っている場合です。例: eat と tea 。アナグラムをまとめ、グループのリストを返します。

鍵となる技: 各単語の文字をソートしてキーを作ります。eat と tea はどちらも aet になります。同じキーを持つ単語は同じグループに入れます。キー → 単語リストの辞書を使い、キーが最初に出現した順序を記憶します。

Log in or create account · ⁨ログインまたはアカウント作成⁩

IGCSE, A-Level & AP