-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHasCycle.java
More file actions
44 lines (30 loc) · 856 Bytes
/
HasCycle.java
File metadata and controls
44 lines (30 loc) · 856 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
public class HasCycle {
public static boolean hasCycle(ListNode head) {
ListNode start;
ListNode runner;
if (head ==null || head.next == null){
return false;
}
if (head.next.next != null){
start = head;
runner = head.next.next;
}else{
return false;
}
while (runner != null){
if (start.val == runner.val){
return true;
}
start = start.next;
if (runner.next == null){
return false;
}
runner = runner.next.next;
}
return false;
}
public static void main(String args[]){
ListNode n = null;
System.out.print(HasCycle.hasCycle(n));
}
}