哪个网站专业做安防平利县城乡建设局网站
一、题目

二、思路
- 龟兔进行赛跑 
- 龟的速度是 1,兔的速度是 2
 - 龟兔从同一起点出发,若 龟追上兔 则说明 有环 存在;若追不上,则说明无环。
 
 
三、代码
/*** Definition for singly-linked list.* class ListNode {*     int val;*     ListNode next;*     ListNode(int x) {*         val = x;*         next = null;*     }* }*/
public class Solution {public boolean hasCycle(ListNode head) {// 龟兔位于同一起点ListNode slow = head, fast = head;while(fast != null && fast.next != null) {slow = slow.next;// 龟走1步fast = fast.next.next;// 兔走2步if(fast == slow) {//龟兔相遇->进入环return true;}}return false;}
}
