From 6917b61c586adc2b19b044d2057a75a04a18362b Mon Sep 17 00:00:00 2001 From: QuinnDK <39618652+QuinnDK@users.noreply.github.com> Date: Mon, 17 May 2021 15:50:36 +0800 Subject: [PATCH] =?UTF-8?q?Update=200142.=E7=8E=AF=E5=BD=A2=E9=93=BE?= =?UTF-8?q?=E8=A1=A8II.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0142.环形链表II.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/problems/0142.环形链表II.md b/problems/0142.环形链表II.md index 7556b854..b3a53c07 100644 --- a/problems/0142.环形链表II.md +++ b/problems/0142.环形链表II.md @@ -234,6 +234,29 @@ class Solution: ``` Go: +```func detectCycle(head *ListNode) *ListNode { + if head ==nil{ + return head + } + slow:=head + fast:=head.Next + + for fast!=nil&&fast.Next!=nil{ + if fast==slow{ + slow=head + fast=fast.Next + for fast!=slow { + fast=fast.Next + slow=slow.Next + } + return slow + } + fast=fast.Next.Next + slow=slow.Next + } + return nil +} +``` -----------------------