Javascript 5 lines with inline comment


  • 0
    H
    var getIntersectionNode = function(ah, bh) {
        var a=ah, b=bh
        while(a!=b){
            a = a? a.next : bh // move a to head of b if at end
            b = b? b.next : ah // move b to head of a if at end      
        }
        
        return a; // a === b either happen at the connecting point or when they are both null
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.