49. Group Anagrams.md#13
Open
X-XsleepZzz wants to merge 4 commits into
Open
Conversation
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.
oda
reviewed
Feb 22, 2026
| return list(sorted_str_to_words.values()) | ||
| ``` | ||
| 見直しもしたが、意外とタイポなしでゼロから何回も書けた。 | ||
| 変数名に意味があるから、書いていてコードの意味がより理解しやすくなった気がする。 |
mamo3gr
reviewed
Feb 27, 2026
| def groupAnagrams(self, strs: List[str]) -> List[List[str]]: | ||
| key_to_char = {} | ||
|
|
||
| for char in strs: |
There was a problem hiding this comment.
step2以降では修正されていますが、char だとミスリーディングですね。
Owner
Author
There was a problem hiding this comment.
ご指摘ありがとうございますmm
たしかにそうですね。。この時、charの意味を誤解して書いていました
|
特に違和感ありませんでした 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.