Conversation
| else: | ||
| return None | ||
|
|
||
| fast = head |
There was a problem hiding this comment.
この段階でfastという変数の意味が変わっています。アルゴリズムを知っている人からすると自明ですが、初見だと戸惑うかもしれません。
There was a problem hiding this comment.
コメントありがとうございます。
個人的には速い人(ウサギ)、遅い人(亀)みたいなイメージでfast, slowを使っていましたが確かに分かりずらさもあるかもしれません。
There was a problem hiding this comment.
私も以前同様のコメントをいただきました。
今であれば、fastではなく、originなどという変数名に置き直す気がします。
There was a problem hiding this comment.
コメントありがとうございます。
確かにそれはよい選択肢ですね。
参考にさせていただきます。
| def detectCycle(self, head: Optional[ListNode]) -> Optional[ListNode]: | ||
| visited = set() | ||
|
|
||
| def _check_node(node): |
There was a problem hiding this comment.
inner function の関数名の先頭には _ を付けなくてよいと思います。非 public な関数名には付けたほうがよいと思います。
https://peps.python.org/pep-0008/#method-names-and-instance-variables
Use one leading underscore only for non-public methods and instance variables.
https://google.github.io/styleguide/pyguide.html#3162-naming-conventions
Prepending a single underscore (_) has some support for protecting module variables and functions (linters will flag protected member access).
There was a problem hiding this comment.
コメントありがとうございます。
外部からアクセスしてほしくないときにつけるということですね。
参考にさせていただきます。
| if fast == slow: | ||
| break | ||
| else: | ||
| return None |
There was a problem hiding this comment.
while-else は Python に特徴的な文法です。
整え方にいくつか方法があるので、このあたりを見ておいてください。
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.4qnnfvpo8ij5
There was a problem hiding this comment.
コメントありがとうございます。
参考にさせていただきます。
|
良いと思います、気になるところも特にありません |
問題:https://leetcode.com/problems/linked-list-cycle-ii/description/