text: //Problem Statement
  /*
  Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.
  
  Example Input and Output
  Input: listA = [4,1,8,4,5], listB = [5,6,1,8,4,5]
  Output: Intersected at '8'. Function will return pointer to '8'
  Explanation: The intersected node's value is 8 (note that this must not be 0 if the two lists intersect).
  From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B.
  
  */
  //Definition for singly-linked list.
    struct ListNode {
        int val;
        ListNode *next;
        ListNode(int x) : val(x), next(nullptr) {}
    };
   
  class Solution {
  public:    
      ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
          if(!headA || !headB){
              return nullptr;
          }    
          ListNode *ptr1=headA, *ptr2=headB;
          while(ptr1 && ptr2){
              if(ptr1==ptr2)
              return ptr1;
              ptr1=ptr1->next;
              ptr2=ptr2->next;
              if(ptr1==ptr2)
              return ptr1;
              if(ptr1==nullptr)
              ptr1=headB;
              if(ptr2==nullptr)
              ptr2=headA;
          }
              return ptr1;
      }
  };
  