Linked List Cycle

//快慢指针 public class Solution { public boolean hasCycle(ListNode head) { if(head==null)return false; ListNode slow=head; ListNode fast=head; do{ if(fast==null||fast.next==null)return false; fast=fast.next.next; slow=slow.next; } while(fast!=slow); return true; } }
相关文章
相关标签/搜索