Group anagrams · 아나그램 그룹화
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가 됩니다. 동일한 키를 가진 단어는 같은 그룹에 속합니다. 키 → 단어 목록으로 되는 사전(dictionary)을 사용하고, 키가 처음 나타나는 순서를 기억해 두십시오.
Write group_anagrams(words) that groups words which are anagrams of each other. Return a list of groups: words keep their original order inside a group, and groups are ordered by first appearance. · 서로 아나그램인 단어들을 그룹화하는 group_anagrams(words)을 작성하세요. 그룹의 목록을 반환하며, 그룹 내에서는 단어가 원래 순서를 유지하고, 그룹끼리는 첫 번째 등장 순서에 따라 정렬됩니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.