链表交叉节点

let intersection = {
    val:3,
    next:{
        val:4,
        next:{
            val:5,
            next:null
        }
    }
}
  
let linkListA = {
    val:1,
    next:{
        val:2,
        next:intersection
    }
}

let linkListB= {
    val:-1,
    next:{
        val:-2,
        next:{
            val:1,
            next:{
                val:2,
                next:intersection
            }
        }
    }
}

function intersectionLinkList(l1 = linkListA,l2 = linkListB){
    let weakMap = new WeakMap()
    let l1_next = l1.next,l2_next = l2.next
    while(l1_next != null){
        if(!weakMap.has(l1_next)){
            weakMap.set(l1_next,l1_next)
        }
        l1_next = l1_next.next
    }
    while(l2_next != null){
        if(weakMap.has(l2_next)){
            return weakMap.get(l2_next)
        }
        l2_next = l2_next.next
    }
}  
原文地址:https://www.cnblogs.com/zhenjianyu/p/13871720.html