-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
特に突っ込みたい点はなかったです、良いと思います |
visited = set() | ||
node = head | ||
|
||
while node is not None and node.next is not None: |
There was a problem hiding this comment.
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
の部分がなくても動きますかね。
There was a problem hiding this comment.
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
フロイドの循環検出法が想定解だと考えて、だと思います。
LeetCode の難易度はあまり参考にならないのであまり気にしなくていいでしょう。
(本来のゴールは動くコードが書けるかどうかではないのだけれども、そのあたりの感覚がなさそうです。)
プルリク名は「142. Linked List Cycle II」とすると良いでしょう。 |
誰かの発言の引用は「」でおこなう | ||
|
||
step1 | ||
```python |
There was a problem hiding this comment.
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で返すべきだった |
There was a problem hiding this comment.
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.
とありますね。
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
難易度とは関係ないでしょう。
ありがとうございます。修正いたしました |
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