Skip to content

142. Linked List Cycle Ⅱ#9

Open
Yuto729 wants to merge 2 commits intomainfrom
linked-list-cycle-ii
Open

142. Linked List Cycle Ⅱ#9
Yuto729 wants to merge 2 commits intomainfrom
linked-list-cycle-ii

Conversation

@Yuto729
Copy link
Owner

@Yuto729 Yuto729 commented Nov 24, 2025

@Yuto729 Yuto729 changed the title Linked List Cycle Ii Linked List Cycle Ⅱ Nov 24, 2025
Repository owner deleted a comment from github-actions bot Nov 24, 2025
@Yuto729 Yuto729 changed the title Linked List Cycle Ⅱ 142. Linked List Cycle Ⅱ Nov 24, 2025
Comment on lines +38 to +41
while fast != slow:
fast = fast.next
slow = slow.next

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここのみ違っていたため直し忘れかと思いますが、今回は同一性を確かめる必要があるため、is not が適切のように思います。

Suggested change
while fast != slow:
fast = fast.next
slow = slow.next
while fast is not slow:
fast = fast.next
slow = slow.next

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本当ですね!ありがとうございます

@TakayaShirai
Copy link

一点コメントしましたが、それ以外の部分は読みやすかったです!

slow = slow.next
fast = fast.next.next

# デフォルトでは, __eq__メソッドではオブジェクトの等価性を見ているので `==` で記述しても同じだが以下のように記述するほうが厳密. `is`はポインタの比較?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以下のようにドキュメントに記載があり、id()はオブジェクトのメモリアドレスを取得するとあります。ポインタが指すメモリアドレスの同一性チェックという意味で大丈夫そうです。

オブジェクトの同一性は id() 関数を使って判定されます。

https://docs.python.org/ja/3/reference/expressions.html#is-not

https://docs.python.org/ja/3/library/functions.html#id:~:text=%E3%81%93%E3%82%8C%E3%81%AF%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AE%E3%83%A1%E3%83%A2%E3%83%AA%E3%82%A2%E3%83%89%E3%83%AC%E3%82%B9%E3%81%A7%E3%81%99

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

補足ありがとうございます!

Copy link

@fv17 fv17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

読みやすかったです!

Comment on lines +110 to +111
from_start = head
from_intersection = intersection
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from_start, from_intersection の変数名分かりやすかったです。
from_head もアリな気がしました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants