/*function ListNode(x){
    this.val = x;
    this.next = null;
}*/
function FindFirstCommonNode(l1, l2)
{
    if (!l1 || !l2) return null;
   
    let set = new Set();
    let p1 = l1;
    let p2 = l2;
  
    while (p1) {
        set.add(p1);
        p1 = p1.next;
    }
    
    while(p2) {
        // if we find node from p2 that is in our set, then return the node
        if (set.has(p2)) return p2;
        p2 = p2.next;
    } 
    
    return null;
}
module.exports = {
    FindFirstCommonNode : FindFirstCommonNode
};