Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
detect cycle in singly linked list
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class ListNode { int val; ListNode next; ListNode(int x) { val = x; next = null; } } class Rextester { public static boolean hasCycle(ListNode head) { if(head==null||head.next==null||head.next.next==null) return false; ListNode one = head; ListNode two = head.next; while(one!=null&&two!=null){ if(one==two){ return true; } if(one.next==null) return false; if(two.next==null) return false; if(two.next.next==null) return false; one = one.next; two = two.next.next; } return false; } public static void main(String args[]) { System.out.println("Hello, World!"); } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
brindtuch
Sum of power of digits-1
Armstrong no
Main
Java messing around
fizzbuzz
Rextester.java
ElaineBrown**
Increment Operator
JAVA # Klavyeden girilen cümlede kaç adet "a" harfi var
Please log in to post a comment.