Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool hasCycle(ListNode *head) {
- if(!head){
- return false;
- }
- ListNode* lento;
- ListNode* rapido;
- lento = rapido = head;
- while(true){
- lento = lento->next;
- if(rapido->next){
- rapido = rapido->next->next;
- }else{
- return false;
- }
- if(!lento || !rapido){
- return false;
- }
- if(lento == rapido){
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement