We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 263e2a4 commit 490abd7Copy full SHA for 490abd7
go/linked-list-cycle.go
@@ -0,0 +1,29 @@
1
+package main
2
+
3
+/**
4
+ * Definition for singly-linked list.
5
+ * type ListNode struct {
6
+ * Val int
7
+ * Next *ListNode
8
+ * }
9
+ */
10
11
+// https://leetcode.com/problems/linked-list-cycle/
12
+func hasCycle(head *ListNode) bool {
13
+ if head == nil || head.Next == nil || head.Next.Next == nil {
14
+ return false
15
+ }
16
17
+ slow := head
18
+ fast := head.Next.Next
19
20
+ for fast.Next != nil && fast.Next.Next != nil {
21
+ if slow == fast {
22
+ return true
23
24
+ slow = slow.Next
25
+ fast = fast.Next.Next
26
27
28
29
+}
0 commit comments