Files
LeetCode-Go/leetcode/0141.Linked-List-Cycle/141. Linked List Cycle.go
Breno Baptista c8aa2a477e Fixed definition
2021-07-17 00:36:07 -03:00

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
}