Conversation
| class Solution: | ||
| def wordBreak(self, s: str, wordDict: List[str]) -> bool: | ||
| string_length = len(s) | ||
| breakableTo = [True] + [False] * string_length |
There was a problem hiding this comment.
変数名は snake case にするのが一般的だと思います。
https://peps.python.org/pep-0008/#function-and-variable-names
breakableTo のTo については意味を読み取ることができませんでした。
また、string_length は変数にするほど重要でない、len(s) より情報量が増えていない気がしました。
There was a problem hiding this comment.
breakableTo[i]とすれば英文的には分かりやすいのかなと思っていました
また、string_lengthについては二回呼び出すので保持しても良いのかなと思いましたが確かにない方が良いですかね
There was a problem hiding this comment.
ただの一意見ですが、自分もlen(s)をそのまま使ってしまって良いと思いました。
理由としては、len(s)はそもそも可読性が高い。string_lengthの変数名が少し長い。ためです。
| if start in triedFrom: | ||
| continue | ||
| triedFrom.add(start) | ||
| for i in word_lengths: |
There was a problem hiding this comment.
i より word_length の方が読みやすいと思いました。初め word_lengths の役割がわからなかったので、word_length_to_words = {文字数: list[単語]} のようにするとわかりやすくなるかもしれません。もしくはコメントで補足するのもありでしょうか。
|
全体的に、もう少し改行があると読みやすいかな?と思いました。好みかもしれませんし、無駄に改行が多いよりは良いと思います。 |
問題文:https://leetcode.com/problems/word-break/description/