Skip to content

Commit 4681cbc

Browse files
add Solution 0141 [golang]
1 parent f133f3e commit 4681cbc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @lc app=leetcode.cn id=141 lang=golang
3+
* 17/17 cases passed (12 ms), memory usage 4 MB
4+
*/
5+
func hasCycle(head *ListNode) bool {
6+
if head == nil || head.Next == nil {
7+
return false
8+
}
9+
slow, fast := head, head.Next
10+
for {
11+
if fast == nil || fast.Next == nil {
12+
return false
13+
}
14+
if slow == fast {
15+
return true
16+
}
17+
slow, fast = slow.Next, fast.Next.Next
18+
}
19+
return false
20+
}

0 commit comments

Comments
 (0)