Notes:
1 /** 2 * Created by sheepcore on 2019-05-14 3 * Definition for singly-linked list. 4 * class ListNode { 5 * int val; 6 * ListNode next; 7 * ListNode(int x) { 8 * val = x; 9 * next = null; 10 * } 11 * } 12 */ 13 public boolean hasCycle(ListNode head) { 14 ListNode p = head,pre = head; 15 while(p != null && p.next != null){ 16 if (p.next == head) return true; 17 p = p.next; 18 pre.next = head; 19 pre = p; 20 } 21 return false; 22 }
LeetCode-141 Linked List Cycle Solution (with Java)
原文:https://www.cnblogs.com/sheepcore/p/12395121.html