public void createCycle(){ //创建环
Node cur = head;
while(cur.next != null){
cur = cur.next;
}
cur.next = head.next;
//是否有环,走两步 走一步
//走三步和走两步的区别
}
public boolean hasCycle(){
Node fast =head;
Node slow = head;
while(fast != null && fast.next != null){
fast = fast.next.next;
slow = slow.next;
//每一次发生变化,这里都需要进行判断
if(fast == slow){
break;
}
}
if (fast != null && slow !=null && fast == slow){
return true;
}
return false;
}