DSA Day 69/100

DSA Day 69/100

Topic: Linked List

Questions Successfully Completed: 1

1) Check if it is a circular Linked List

Easy

Question
Input: LinkedList: 1->2->3->4->5 (the first and last node is connected, i.e. 5 --> 1) Output: 1
class GfG
{
    boolean isCircular(Node head)
    {
      if (head ==null){
          return true;
      }

      Node p = head;

      while(p.next!=head){
          p=p.next;
          if(p==null){
              return false;
          }
      }
      return true;
    }
}

Thank you for reading :)