forked from DreamCats/java-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT6.java
More file actions
28 lines (26 loc) · 696 Bytes
/
T6.java
File metadata and controls
28 lines (26 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* @program JavaBooks
* @description: 环形链表
* @author: mf
* @create: 2020/04/09 17:24
*/
package subject.dpointer;
public class T6 {
public boolean hasCycle(ListNode head) {
if (head != null && head.next != null) {
// 快慢指针
ListNode quick = head;
ListNode slow = head;
while (2 > 1) {
quick = quick.next;
if (quick == null) return false;
quick = quick.next;
if (quick == null) return false;
slow = slow.next;
if (slow == quick) return true;
}
} else {
return false;
}
}
}