mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-23 09:51:45 +08:00
31 lines
512 B
Go
31 lines
512 B
Go
package leetcode
|
|
|
|
import (
|
|
"github.com/halfrost/LeetCode-Go/structures"
|
|
)
|
|
|
|
// ListNode define
|
|
type ListNode = structures.ListNode
|
|
|
|
/**
|
|
* Definition for singly-linked list.
|
|
* struct ListNode {
|
|
* int val;
|
|
* ListNode *next;
|
|
* ListNode(int x) : val(x), next(NULL) {}
|
|
* };
|
|
*/
|
|
|
|
func hasCycle(head *ListNode) bool {
|
|
fast := head
|
|
slow := head
|
|
for slow != nil && fast != nil && fast.Next != nil {
|
|
fast = fast.Next.Next
|
|
slow = slow.Next
|
|
if fast == slow {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|