File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
LeetCodePrj/Java/leetcode Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ package leetcode .common ;
2+
3+ /**
4+ * @author Kyle
5+ * @create 2018/8/23 1:10
6+ */
7+ public class ListNode {
8+ public int val ;
9+ public ListNode next ;
10+ public ListNode (int x ) {
11+ val = x ;
12+ next = null ;
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ package leetcode .easy ;
2+
3+ import leetcode .common .ListNode ;
4+
5+ /**
6+ * @author Kyle
7+ * @create 2018/8/23 1:08
8+ */
9+ public class LinkedListCycle {
10+ public boolean hasCycle (ListNode head ) {
11+ if (head == null ) {
12+ return false ;
13+ }
14+
15+ ListNode fast = head ;
16+ ListNode slow = head ;
17+
18+ while (fast .next != null && fast .next .next != null ) {
19+ slow = slow .next ;
20+ fast = fast .next .next ;
21+ if (fast != null && slow == fast ) {
22+ return true ;
23+ }
24+ }
25+
26+ return false ;
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments