题解 | #判断链表中是否有环#
判断链表中是否有环
http://www.nowcoder.com/practice/650474f313294468a4ded3ce0f7898b9
/**
*
* @param head ListNode类
* @return bool布尔型
*/
// 快慢指针解决
func hasCycle( head *ListNode ) bool {
// write code here
fast := head
slow := head
for fast != nil && fast.Next != nil {
fast = fast.Next.Next
slow = slow.Next
if fast == slow {
return true
}
}
return false
}