Skip to content

Instantly share code, notes, and snippets.

@abdulrahmanAlotaibi
Created December 15, 2022 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdulrahmanAlotaibi/d23658de46186a2370e6f69edf4cbff8 to your computer and use it in GitHub Desktop.
Save abdulrahmanAlotaibi/d23658de46186a2370e6f69edf4cbff8 to your computer and use it in GitHub Desktop.
Linkedlists : Linked List Cycle
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func hasCycle(head *ListNode) bool {
dummy := head
arr := []*ListNode{}
for dummy != nil {
for _, n := range arr {
if dummy.Next == n {
return true
}
}
arr = append(arr, dummy)
dummy = dummy.Next
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment