Conversation
| word_set.discard(beginWord) | ||
|
|
||
| begin_frontier = {beginWord} | ||
| end_frontier = {endWord} |
There was a problem hiding this comment.
細かいですが、snake_caseとlowerCamelCaseが入り混じった変数名には意図があるのか気になりました。
There was a problem hiding this comment.
引数がCamel Caseで自分が使っているのがsnake_caseなのでこうなってしまいました。
これを気持ち悪いと思う感覚は大事ですね
There was a problem hiding this comment.
本当は LeetCode のシグネイチャーが標準的な記法に従っていないのですが、Python の場合は、keyword 呼び出しがあるので、シグネイチャーを変えると意味が変わる可能性がありますね。
There was a problem hiding this comment.
https://docs.python.org/3/tutorial/controlflow.html#special-parameters
pos_only, /, standard, *, kwd_only と書くこと、知らなかったです。勉強になりました。
| from collections import defaultdict | ||
|
|
||
|
|
||
| class NeighborWords: |
There was a problem hiding this comment.
クラスが機能するために必要な情報はコンストラクタ(あるいはbuilderなど)で与えられるべきです。from_wordsを最初に絶対に使わないと使い間違えるクラスになっていませんか?
また、from_wordsは何度でも呼び出せる必要があるものでしょうか?そうでないならばクラス生成後はこのメソッドを叩けないのが望ましいです
There was a problem hiding this comment.
classmethodなどは使わずに def init(self, words): とするべきですね。ご指摘のとおりだと思います。
https://leetcode.com/problems/word-ladder/description/