力扣-141.环形链表
题目链接
141.环形链表
public class Solution {public boolean hasCycle(ListNode head) {ListNode slow = head;if (head.next == null) return false;ListNode fast = head.next;while (fast.next != null && fast.next.next != null && fast != slow) {fast = fast.next.next;slow = slow.next;}if (fast == slow)return true;return false;}
}
小结:快慢指针秒了!!!