49. Group Anagrams#32
Open
skypenguins wants to merge 1 commit into
Open
Conversation
MA-yo-TA
reviewed
Jun 18, 2026
| - 2回目: 1:22 | ||
| - 3回目: 1:24 | ||
|
|
||
| - 書いた後だけど `sorted_strs` は `strs_by_sorted_strs` とかの方がわかりやすいな |
There was a problem hiding this comment.
sorted_string_to_group とかでも良いかもしれません。
| break | ||
| ``` | ||
|
|
||
| ### 正答 |
There was a problem hiding this comment.
今回されている考察を一般化した考え方として、
複数の要素を、なにかしらの基準をもとに「同じだ」といえる要素同士のグループに分けるとき、
- 2つの要素を比較して、それらが同じグループに入るのかを考える
よりも、
- 1つの要素を見て、それがどのグループに属するかを判定する
ほうが効率が良い、と言えるのかなと思いました。
どのグループに属するかの判定をする時にはそのグループ固有の条件とか「名前」みたいなものが必要で、今回は
- ソートした文字列
- 文字の出現回数を数えたデータ
あたりが使える、ということなのかなと思っています。
Owner
Author
There was a problem hiding this comment.
コメントありがとうございます。
1つの要素を見て、それがどのグループに属するかを判定する
たしかに仰る通りで、2つの条件を比較するよりまずシンプルにできないかの方針で今後は考えてみます。
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.
49. Group Anagrams