Created
March 28, 2020 22:05
-
-
Save alldroll/c290ba49cfc9df38dcd260a50c3d6ac0 to your computer and use it in GitHub Desktop.
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 characters
| // https://leetcode.com/problems/linked-list-cycle/ | |
| /** | |
| * Definition for singly-linked list. | |
| * type ListNode struct { | |
| * Val int | |
| * Next *ListNode | |
| * } | |
| */ | |
| func hasCycle(head *ListNode) bool { | |
| hare := head | |
| tortoise := head | |
| for hare != nil && hare.Next != nil { | |
| hare = hare.Next.Next | |
| tortoise = tortoise.Next | |
| if hare != nil && hare.Val == tortoise.Val { | |
| return true | |
| } | |
| } | |
| return false | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment