public class Solution {
public boolean hasCycle(ListNode head) {
ListNode slow = head;
while(head!=null&&head.next!=null&&head.next.next!=null){
head=head.next.next;
slow = slow.next;
if (head==slow) return true;
}
return false;
}
}
判断链表是否有环
最新推荐文章于 2024-09-01 06:57:03 发布