![]() |
VOOZH | about |
Given a circular linked list. The task is to find the length of the linked list, where length is defined as the number of nodes in the linked list.
The idea is to start from the head node and traversing the list until it loops back to the head. Since a circular linked list has no end, the traversal continues until the current node equals the head again. Increment the counter variable during each step of the traversal of nodes. Finally return the count, which represent the count of nodes in circular linked list.
5
Time Complexity: O(n), where n is the length of given linked list.
Auxiliary Space: O(1)