Skip to content

142. Linked List Cycle II.md #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

142. Linked List Cycle II.md #2

wants to merge 2 commits into from

Conversation

lilnoahhh
Copy link
Owner

@lilnoahhh lilnoahhh 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

@lilnoahhh lilnoahhh changed the title Create 142_Linked_List.md 142_Linked_List.md Jan 6, 2025
@lilnoahhh lilnoahhh changed the title 142_Linked_List.md 142. Linked List.md Jan 6, 2025
@lilnoahhh lilnoahhh changed the title 142. Linked List.md 142. Linked List Jan 6, 2025
@SanakoMeine
Copy link

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

visited = set()
node = head

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

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
Owner Author

Choose a reason for hiding this comment

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

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


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

Copy link

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

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

誰かの発言の引用は「」でおこなう

step1
```python

Choose a reason for hiding this comment

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

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

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

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

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
Owner Author

Choose a reason for hiding this comment

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

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

```

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

Choose a reason for hiding this comment

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

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

@lilnoahhh lilnoahhh changed the title 142. Linked List 142. Linked List Cycle II Jan 7, 2025
@lilnoahhh
Copy link
Owner Author

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

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

@lilnoahhh lilnoahhh 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