1 parent ca2e351 commit 79a398bCopy full SHA for 79a398b
1 file changed
solutions/141. Linked List Cycle/AC_Floyd I.java
@@ -1,32 +0,0 @@
1
- /**
2
- * 1、Floyd判圈法(之前一直叫双指针跑圈法来着)
3
- *
4
5
- */
6
-/**
7
- * Definition for singly-linked list.
8
- * class ListNode {
9
- * int val;
10
- * ListNode next;
11
- * ListNode(int x) {
12
- * val = x;
13
- * next = null;
14
- * }
15
16
17
-public class Solution {
18
- public boolean hasCycle(ListNode head) {
19
- if(head == null || head.next == null)
20
- return false;
21
-
22
- ListNode slow = head;
23
- ListNode fast = head;
24
- do{
25
- if(fast == null || fast.next == null) return false;
26
27
- slow = slow.next;
28
- fast = fast.next.next;
29
- }while(slow != fast);
30
- return true;
31
- }
32
-}
0 commit comments