Run Code
|
API
|
Code Wall
|
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
Cola Machine
4b
[Java] Coding - Reverse CODE - Mathematical Method
CRUD vehicules
victory1
Series_4_8
Oh no
JAVA sidebar pattern match
piglatin
post decrement