-
Notifications
You must be signed in to change notification settings - Fork 0
Solved Arai60/139. Word Break #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
変数名は 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
breakableTo[i]とすれば英文的には分かりやすいのかなと思っていました
また、string_lengthについては二回呼び出すので保持しても良いのかなと思いましたが確かにない方が良いですかね
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ただの一意見ですが、自分も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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i より word_length の方が読みやすいと思いました。初め word_lengths の役割がわからなかったので、word_length_to_words = {文字数: list[単語]} のようにするとわかりやすくなるかもしれません。もしくはコメントで補足するのもありでしょうか。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確かにそれありですね。ありがとうございます!
全体的に、もう少し改行があると読みやすいかな?と思いました。好みかもしれませんし、無駄に改行が多いよりは良いと思います。 |
問題文:https://leetcode.com/problems/word-break/description/