Closed underwindfall closed 2 years ago
https://leetcode-cn.com/problems/c32eOV/
思路
[x] 刷15mins
[x] 刷5mins
// time O(n) // space O(1) public ListNode detectCycle(ListNode head) { ListNode fast = head, slow = head; while (fast != null) { if (fast.next != null) { fast = fast.next.next; } else { return null; } slow = slow.next; if (fast == slow) { break; } } if (fast == null) { return null; } ListNode start = head; while (start != slow) { start = start.next; slow = slow.next; } return slow; }
https://leetcode-cn.com/problems/c32eOV/
思路
[x] 刷15mins
[x] 刷5mins