We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
staticbooleanhasCycle(SinglyLinkedListNodehead){SinglyLinkedListNodefast=head;SinglyLinkedListNodeslow=head;if(head==null)returnfalse;while(fast!=null&&fast.next!=null){//move the fast poitnet by 2 nodes next and slow pointer by one node nextfast=fast.next.next;slow=slow.next;//compaire fast and slow pointer address , if matches then cycle detected.if(fast==slow){returntrue;}}returnfalse;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cycle Detection
You are viewing a single comment's thread. Return to all comments →
JAVA: Here is my resolution for this problem: