Delete comment from: Javarevisited
@Anonymous, No, that's not correct, because if fast is null means linked list is not cyclic. But original code is also not correct and will throw NullPointerException if fast is null. Instead of just checking while(fast.next != null), it should check while(fast != null && fast.next != null), that way code will prevent NullPointerException. I think author, just missed this condition.
May 30, 2013, 5:12:09 AM
Posted to How to find If Linked List Contains Loop or Cycle in Java? Example Solution

