Skip to content

141. Linked List Cycle#8

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

141. Linked List Cycle#8
Yuto729 wants to merge 2 commits intomainfrom
linked-list-cycle

Conversation

@Yuto729
Copy link
Owner

@Yuto729 Yuto729 commented Nov 22, 2025

解く問題

Linked List Cycle

次に解く問題

Linked List Cycle Ii

@Yuto729 Yuto729 changed the title Linked List Cycle 141. Linked List Cycle Nov 22, 2025
fast = head
slow = head

while fast and fast.next:
Copy link

@KDB017 KDB017 Nov 23, 2025

Choose a reason for hiding this comment

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

fastとfast.nextの条件文は明確にNoneだけを否定できるis not Noneを使った方が良いと思います!今の状態だと()とかも判定に含まれているので

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます!

Repository owner deleted a comment from github-actions bot Nov 23, 2025
return True

visited.add(val)
head = head.next
Copy link

Choose a reason for hiding this comment

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

head は連結リスト先頭のノードを表す単語です。 head が移動していくのは違和感があります。 node 等、一度別の変数に代入し、そちらを動かしていったほうが自然に感じます。

Copy link

@appseed246 appseed246 Nov 26, 2025

Choose a reason for hiding this comment

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

自分も野田さんと同様に、変数nodeに代入してからのほうが良いと思いました。

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

if fast == slow:
Copy link

Choose a reason for hiding this comment

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

比較には ==、 is などのどれを使うべきか意識しよう、というコメントが多々ありましたので一例を添付いたします。ご参考までに。

参考:
https://github.com/SakaiYuzuki/LeetCode_arai60/pull/1/files#r2444784687

Copy link
Owner Author

Choose a reason for hiding this comment

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

この場合はisが良さそうですね

Choose a reason for hiding this comment

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

問題には関係ないのですが気になったので一応コメントします。

こちらのファイルですが、create-pr.shによって書き換えられたテンプレートがコミットされたものでしょうか?(最新のスクリプトではコミットしないようになっていることは確認できました。)
実際の実務を想定するならば、マージ対象でないファイルはプルリクエストから除外したほうがよいかなと思います。

また、create-pr.shの処理についてですが、ファイルを直接上書きするとgit上で変更のあるファイルとして認識されてしまい、コミット時に除外する手間があるのかなと思うので、テンプレートの内容をsedなどで置換し、gh pr createコマンドの--bodyオプションに置換したテキストの内容を渡してプルリクを作成するファイルの変更がでなくてよいかと思いました。

参考: https://cli.github.com/manual/gh_pr_create

-b, --body
Body for the pull request

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.

5 participants