/***
* 用快慢指针判断链表是否有环
* @param head
* @return
*/
public boolean isCircleLinkedListNode(ListNode head){
if(head == null){
return false;
}
ListNode slow = head,fast = head;
if(fast.next !=null && fast.next.next!=null){
slow =slow.next;
fast = fast.next.next;
if(slow == fast){
return true;
}
}
return false;
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交