thafnhlong / hackerrank-storage

0 stars 0 forks source link

https://www.hackerrank.com/challenges/detect-whether-a-linked-list-contains-a-cycle #9

Open thafnhlong opened 2 years ago

thafnhlong commented 2 years ago

image

p1=> (pointer to ll ).next if(p1==null) return false; p2=> p1.next; if (p2==null) return false; while(p1 != null && p2!=null && p2->next != null){ if(p1==p2) return true p1=p1.next; p2=p2.next.next; }

return false