Skip to content

141. Linked List Cycle#2

Open
hemispherium wants to merge 2 commits intomainfrom
0141-linked-list-cycle
Open

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

Conversation

@hemispherium
Copy link
Owner

@hemispherium hemispherium self-assigned this Dec 9, 2025
@@ -0,0 +1,11 @@
### step1

グラフのサイクル検出アルゴリズムで解こうとしたが、実装が主いつなかったので、ChatGPTに提示されたフロイドの循環検出アルゴリズム(https://note.com/rhayahi/n/n7fc11c09fec6)で解いた。
Copy link

Choose a reason for hiding this comment

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

フロイドのうさぎとかめは知らなかったのですが、setの方での実装をsolution2.cppというファイルで書き直しておきました。

class Solution {
public:
bool hasCycle(ListNode *head) {
if (head == nullptr) return false;
Copy link

Choose a reason for hiding this comment

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

この行はあってもいいですが、なくてもいいですね。(意図としては、よしあしがあるので書いても書かなくてもいいが、動作が変わるかを考えておきましょうということです。)

Copy link
Owner Author

Choose a reason for hiding this comment

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

動作がどう変わるかは考えるようにします。


### step2

L11の部分をhead == nullptrに書き直した。

Choose a reason for hiding this comment

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

step2で参照したreferenceやGitHubなどリンクを貼っておくと後の学習に役立つと思います。

スタイルなどを参照したい時は下記も役に立つかと思います。あくまで参考ですが、一つ基準があると良いそうです。
https://google.github.io/styleguide/cppguide.html

Copy link
Owner Author

Choose a reason for hiding this comment

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

コメントありがとうございます!承知しました。

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.

3 participants