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.
Thank you for great solution, however why is it the case that in C++ fast hast to point to head's next as opposed to both slow and fast pointing to head in Java. Thanks.
boolhas_cycle(Node*head){// Complete this function// Do not write the main methodif(head==NULL)returnfalse;Node*slow=head;Node*fast=head->next;while(fast!=NULL&&fast->next!=NULL){slow=slow->next;fast=fast->next->next;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 →
Thank you for great solution, however why is it the case that in C++ fast hast to point to head's next as opposed to both slow and fast pointing to head in Java. Thanks.