public boolean hasCycle(ListNode head) {
if(null==head||head.next==null){
return false;
}
ListNode slow=head;
ListNode fast=head.next;
while(slow!=fast){
if(fast==null||fast.next==null){
return false;
}
slow=slow.next;
fast=fast.next.next;
}
return true;
}
判断链表中是否有环
最新推荐文章于 2025-12-18 13:12:06 发布
484

被折叠的 条评论
为什么被折叠?



