Created
January 22, 2025 08:09
-
-
Save GabrielModog/e0e4d74c0fe31be2c0c08ea566db10dd to your computer and use it in GitHub Desktop.
Revisions
-
GabrielModog created this gist
Jan 22, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ package main import ( "fmt" ) type Node { value string next *Node } func HasCycleNode(root *Node) bool { if root == nil { return false } current, ahead := root, root for ahead != nil && ahead.next != nil { current = root.next ahead = root.next.next if slow === ahead { return true } } return false } func main() { node1 := &Node{ value: "A" } node2 := &Node{ value: "B" } node3 := &Node{ value: "C" } node4 := &Node{ value: "D" } node1.next = node2 node4.next = node3 node3.next = node4 fmt.Println("Cycle node:", HasCycleNodes(node1)) }