diff --git a/Java/Algorithms/LinkedList/LinkedListCycle b/Java/Algorithms/LinkedList/LinkedListCycle new file mode 100644 index 000000000..3c389bbd4 --- /dev/null +++ b/Java/Algorithms/LinkedList/LinkedListCycle @@ -0,0 +1,13 @@ +public class LinkedListCycle { + public boolean hasCycle(ListNode head) { + ListNode fast = head; + ListNode slow = head; + while(fast != null && fast.next != null){ + fast = fast.next.next; + slow = slow.next; + if(fast == slow) + return true; + } + return false; + } +}