Skip to content

142. Linked List Cycle II.md#2

Open
X-XsleepZzz wants to merge 2 commits into
mainfrom
lilnoahhh-patch-2
Open

142. Linked List Cycle II.md#2
X-XsleepZzz wants to merge 2 commits into
mainfrom
lilnoahhh-patch-2

Conversation

@X-XsleepZzz
Copy link
Copy Markdown
Owner

@X-XsleepZzz X-XsleepZzz commented Jan 6, 2025

142. Linked List Cycle II

Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.

There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to (0-indexed). It is -1 if there is no cycle. Note that pos is not passed as a parameter.

Do not modify the linked list.

次は83. Remove Duplicates from Sorted List

@X-XsleepZzz X-XsleepZzz changed the title Create 142_Linked_List.md 142_Linked_List.md Jan 6, 2025
@X-XsleepZzz X-XsleepZzz changed the title 142_Linked_List.md 142. Linked List.md Jan 6, 2025
@X-XsleepZzz X-XsleepZzz changed the title 142. Linked List.md 142. Linked List Jan 6, 2025
@SanakoMeine
Copy link
Copy Markdown

特に突っ込みたい点はなかったです、良いと思います

Comment thread 142_Linked_List.md
visited = set()
node = head

while node is not None and node.next is not None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

and node.next is not None
の部分がなくても動きますかね。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

あ、たしかにそうですね。何も考えずに書いていました。ありがとうございます

Comment thread 142_Linked_List.md

振り返ってみると前回の141. Linked List Cycleとあまり変わらない
おそらく型アノテーションの知識もプラスで問われているのでmediumになったのかな(141. Linked List Cycleはeasy)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

フロイドの循環検出法が想定解だと考えて、だと思います。

LeetCode の難易度はあまり参考にならないのであまり気にしなくていいでしょう。

(本来のゴールは動くコードが書けるかどうかではないのだけれども、そのあたりの感覚がなさそうです。)

@liquo-rice
Copy link
Copy Markdown

プルリク名は「142. Linked List Cycle II」とすると良いでしょう。

Comment thread 142_Linked_List.md
誰かの発言の引用は「」でおこなう

step1
```python
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

バグのあるコードは明示するようにすると、レビュワーにとって親切でしょう。

Comment thread 142_Linked_List.md
今までの話をまとめると、以下のコードの意味は引数headはListNodeの属性だがNoneも含む、返り値も同様という意味
def detectCycle(self, head: Optional[ListNode]) -> Optional[ListNode]:

そのため循環がない場合の返り値は-1ではなくNoneで返すべきだった
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

あまり問題文を読めていない印象を受けました。

問題文には

Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.

とありますね。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

あ、たしかに型アノテーションを見なくても問題文に書いていましたね。問題文の指摘ありがとうございます

Comment thread 142_Linked_List.md
```

振り返ってみると前回の141. Linked List Cycleとあまり変わらない
おそらく型アノテーションの知識もプラスで問われているのでmediumになったのかな(141. Linked List Cycleはeasy)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

難易度とは関係ないでしょう。

@X-XsleepZzz X-XsleepZzz changed the title 142. Linked List 142. Linked List Cycle II Jan 7, 2025
@X-XsleepZzz
Copy link
Copy Markdown
Owner Author

プルリク名は「142. Linked List Cycle II」とすると良いでしょう。

ありがとうございます。修正いたしました

@X-XsleepZzz X-XsleepZzz changed the title 142. Linked List Cycle II 142. Linked List Cycle II.md Jan 7, 2025
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