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.

ไทย

กลุ่ม anagram

สองคำเป็น anagram หากใช้ตัวอักษรเหมือนกันเป๊ะ, เช่น eat และ tea. Group anagram เข้าด้วยกันและ return ลิสต์ของกลุ่ม

เทคนิค: sort ตัวอักษรของแต่ละคำเพื่อทำเป็น key — eat และ tea กลายเป็น aet. คำที่มี key เดียวกันอยู่ในกลุ่มเดียวกัน. ใช้ dict จาก key → list of คำ, และจำลำดับที่ key ปรากฏครั้งแรก

Log in or create account · ⁨เข้าสู่ระบบหรือสร้างบัญชี⁩

IGCSE, A-Level & AP