TypeScript

function getIntersectionNode(headA: ListNode | null, headB: ListNode | null): ListNode | null {
    let set =new Set<ListNode>()
    let cur = headA
    while(cur){
        set.add(cur)
        cur=cur.next
    }
    let curB = headB
    while(curB){
        if(set.has(curB)){
            return curB
        }
        curB = curB.next
    }
    return null
};

更多推荐