3. Given the following TypeScript code, what will be the output printed?
class ListNode {
val: number;
next: ListNode | null;
constructor(val: number) {
this.val = val;
this.next = null;
}
}
function getIntersectionNode(headA: ListNode | null, headB: ListNode | null): ListNode | null {
let pA = headA;
let pB = headB;
while (pA !== pB) {
pA = pA ? pA.next : headB;
pB = pB ? pB.next : headA;
}
return pA;
}
// Create nodes
const common = new ListNode(8);
common.next = new ListNode(10);
const listA = new ListNode(3);
listA.next = new ListNode(7);
listA.next.next = common;
const listB = new ListNode(99);
listB.next = common;
const intersection = getIntersectionNode(listA, listB);
console.log(intersection ? intersection.val : null);