N^2 JS solution


  • 0
    L
    function numberOfBoomerangs(points) {
        let res = 0;
        
        points.forEach(p1 => {
            const map = {};
            points.forEach(p2 => {
                const dist = Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2);
                res += (map[dist] || 0) * 2;
                map[dist] = (map[dist] || 0) + 1;
            });
        });
        
        return res;
    }
    

Log in to reply
 

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