Tuesday, January 15, 2019

Loop Detection in a Linked List

Problem Statement: Given a linked list head pointer, you need to output 1 if the list contains a loop or 0 if it doesn't.

This is two pointer approach. You can also solve this using a HashSet of node addresses to see if same node address appeared again or not.

Function:


No comments:

Post a Comment