127. Word Ladder#19
Open
hemispherium wants to merge 1 commit into
Open
Conversation
nodchip
reviewed
Apr 11, 2026
| return 0; | ||
| } | ||
|
|
||
| queue<pair<string, int>> q; |
There was a problem hiding this comment.
q はキューを表しているのでしょうか。
変数を型名にしても、読み手にとって得られる情報はあまりないように思いました。変数名には、どのような値が格納されているかが分かる名前を付けると、より読みやすくなると思います。
また、個人的には、コンテナの変数名は、複数形を表す s で終えるようにしています。 word_and_lengths や word_and_steps はいかがでしょうか?
Owner
Author
There was a problem hiding this comment.
そうですね、word_and_lengths や word_and_stepsの方がよさそうです。
| } | ||
|
|
||
| queue<pair<string, int>> q; | ||
| q.push({ beginWord, 1 }); |
There was a problem hiding this comment.
std::queue::emplace() を使用すると、要素の型のコンストラクターの引数を直接指定して、要素を追加することができます。
https://cpprefjp.github.io/reference/queue/queue/emplace.html
q.emplace(beginWord, 1);
Owner
Author
There was a problem hiding this comment.
そうですね、emplaceの方がすっきり書けてよさそうです。
| return 0; | ||
| } | ||
|
|
||
| queue<pair<string, int>> wordToCount; |
There was a problem hiding this comment.
To は、 map や unordered_map の場合に使う印象があります。また、 wordToCount だと、単語の出現回数というニュアンスを感じます。
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.
この問題:https://leetcode.com/problems/word-ladder/description/
次に解く問題:https://leetcode.com/problems/maximum-depth-of-binary-tree/description/