Skip to content

49. Group Anagrams.md#13

Open
X-XsleepZzz wants to merge 4 commits into
mainfrom
X-XsleepZzz-patch-2
Open

49. Group Anagrams.md#13
X-XsleepZzz wants to merge 4 commits into
mainfrom
X-XsleepZzz-patch-2

Conversation

@X-XsleepZzz
Copy link
Copy Markdown
Owner

Given an array of strings strs, group the anagrams together. You can return the answer in any order.

Example 1:

Input: strs = ["eat","tea","tan","ate","nat","bat"]

Output: [["bat"],["nat","tan"],["ate","eat","tea"]]

Explanation:

There is no string in strs that can be rearranged to form "bat".
The strings "nat" and "tan" are anagrams as they can be rearranged to form each other.
The strings "ate", "eat", and "tea" are anagrams as they can be rearranged to form each other.
Example 2:

Input: strs = [""]

Output: [[""]]

Example 3:

Input: strs = ["a"]

Output: [["a"]]

Constraints:

1 <= strs.length <= 104
0 <= strs[i].length <= 100
strs[i] consists of lowercase English letters.

Added problem statement and examples for grouping anagrams.
Updated the problem statement and example outputs for clarity. Refactored the solution code to use defaultdict for better handling of anagrams.
Remove unnecessary line break in constraints section.
Comment thread 49. Group Anagrams.md
return list(sorted_str_to_words.values())
```
見直しもしたが、意外とタイポなしでゼロから何回も書けた。
変数名に意味があるから、書いていてコードの意味がより理解しやすくなった気がする。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

その感覚大事ですね。
自分で書いて覚えやすいものは基本いいと思います。

Comment thread 49. Group Anagrams.md
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
key_to_char = {}

for char in strs:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

step2以降では修正されていますが、char だとミスリーディングですね。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘ありがとうございますmm
たしかにそうですね。。この時、charの意味を誤解して書いていました

@mamo3gr
Copy link
Copy Markdown

mamo3gr commented Feb 27, 2026

特に違和感ありませんでした 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants