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.
boolhas_cycle(Node*head){// Complete this function// Do not write the main methodNode*slowerPtr=head;Node*fasterPtr=head;if((head==nullptr)||(head->next==nullptr)){returnfalse;}while((fasterPtr!=nullptr)&&(fasterPtr->next!=nullptr)){slowerPtr=slowerPtr->next;fasterPtr=fasterPtr->next->next;if(slowerPtr==fasterPtr){returntrue;}}returnfalse;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Linked Lists: Detect a Cycle
You are viewing a single comment's thread. Return to all comments →
C++