题目:给定一个链表,判断链表中是否有环。
关联力扣141题目 https://leetcode-cn.com/problems/linked-list-cycle/
题解:
PHP题解
function hasCycle($head){
if($head == null) return null;
$slow = $head;
$fast = $head->next;
while($slow != $fast){
if($fast == null || $fast->next == null){
return false;
}
$slow = $slow->next;
$fast = $fast->next->next;
}
return true;
}