mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-06 17:44:10 +08:00
30 lines
452 B
Go
30 lines
452 B
Go
package leetcode
|
|
|
|
import (
|
|
"github.com/halfrost/LeetCode-Go/structures"
|
|
)
|
|
|
|
// ListNode define
|
|
type ListNode = structures.ListNode
|
|
|
|
/**
|
|
* Definition for singly-linked list.
|
|
* type ListNode struct {
|
|
* Val int
|
|
* Next *ListNode
|
|
* }
|
|
*/
|
|
|
|
func hasCycle(head *ListNode) bool {
|
|
fast := head
|
|
slow := head
|
|
for fast != nil && fast.Next != nil {
|
|
fast = fast.Next.Next
|
|
slow = slow.Next
|
|
if fast == slow {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|