问题
I am trying to find an algorithm to count the number of nodes in a Circular linked list by using one pointer only.
Does anyone know any algorithm?
回答1:
Try checking this link: https://www.geeksforgeeks.org/count-nodes-circular-linked-list/
We can also use array to keep count of the nodes visited and exit one's the node count becomes 2. But this approach works for linked list with unique elements only.
来源:https://stackoverflow.com/questions/55487427/circular-linked-list-count-number-of-nodes