Intuitive Javascript Solution


  • 0
    D
    var numberOfBoomerangs = function(points) {
        let count = 0;
        
        for (let i = 0; i < points.length; i++) {
            const memory = {};
    
            for (let j = 0; j < points.length; j++) {
                if (i === j) continue;
                
                // search points with identical distance in memory and count tuples
                const dist = Math.pow(points[i][0] - points[j][0],2) + Math.pow(points[i][1] - points[j][1],2);
                if (memory[dist]) count += memory[dist] * 2;
                
                memory[dist] ? memory[dist] += 1 : memory[dist] = 1;
            }
        }
        
        return count;
    };
    

Log in to reply
 

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