mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
修改(0142.环形链表II.md):优化typescript版本代码
This commit is contained in:
@ -301,13 +301,13 @@ function detectCycle(head: ListNode | null): ListNode | null {
|
||||
let slowNode: ListNode | null = head,
|
||||
fastNode: ListNode | null = head;
|
||||
while (fastNode !== null && fastNode.next !== null) {
|
||||
slowNode = (slowNode as ListNode).next;
|
||||
slowNode = slowNode!.next;
|
||||
fastNode = fastNode.next.next;
|
||||
if (slowNode === fastNode) {
|
||||
slowNode = head;
|
||||
while (slowNode !== fastNode) {
|
||||
slowNode = (slowNode as ListNode).next;
|
||||
fastNode = (fastNode as ListNode).next;
|
||||
slowNode = slowNode!.next;
|
||||
fastNode = fastNode!.next;
|
||||
}
|
||||
return slowNode;
|
||||
}
|
||||
|
Reference in New Issue
Block a user