142. Linked List Cycle II.md#2
Open
X-XsleepZzz wants to merge 2 commits into
Open
Conversation
|
特に突っ込みたい点はなかったです、良いと思います |
oda
reviewed
Jan 6, 2025
| visited = set() | ||
| node = head | ||
|
|
||
| while node is not None and node.next is not None: |
Owner
Author
There was a problem hiding this comment.
あ、たしかにそうですね。何も考えずに書いていました。ありがとうございます
oda
reviewed
Jan 6, 2025
|
|
||
| 振り返ってみると前回の141. Linked List Cycleとあまり変わらない | ||
| おそらく型アノテーションの知識もプラスで問われているのでmediumになったのかな(141. Linked List Cycleはeasy) | ||
|
|
There was a problem hiding this comment.
フロイドの循環検出法が想定解だと考えて、だと思います。
LeetCode の難易度はあまり参考にならないのであまり気にしなくていいでしょう。
(本来のゴールは動くコードが書けるかどうかではないのだけれども、そのあたりの感覚がなさそうです。)
|
プルリク名は「142. Linked List Cycle II」とすると良いでしょう。 |
liquo-rice
reviewed
Jan 6, 2025
| 誰かの発言の引用は「」でおこなう | ||
|
|
||
| step1 | ||
| ```python |
There was a problem hiding this comment.
バグのあるコードは明示するようにすると、レビュワーにとって親切でしょう。
| 今までの話をまとめると、以下のコードの意味は引数headはListNodeの属性だがNoneも含む、返り値も同様という意味 | ||
| def detectCycle(self, head: Optional[ListNode]) -> Optional[ListNode]: | ||
|
|
||
| そのため循環がない場合の返り値は-1ではなくNoneで返すべきだった |
There was a problem hiding this comment.
あまり問題文を読めていない印象を受けました。
問題文には
Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.
とありますね。
Owner
Author
There was a problem hiding this comment.
あ、たしかに型アノテーションを見なくても問題文に書いていましたね。問題文の指摘ありがとうございます
| ``` | ||
|
|
||
| 振り返ってみると前回の141. Linked List Cycleとあまり変わらない | ||
| おそらく型アノテーションの知識もプラスで問われているのでmediumになったのかな(141. Linked List Cycleはeasy) |
Owner
Author
ありがとうございます。修正いたしました |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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