Clear C++ 9 lines 156ms solution beats 99.09%

  • 0
        int distance(pair<int,int>& p1,pair<int,int>& p2){
            return (p1.first-p2.first)*(p1.first-p2.first)+(p1.second-p2.second)*(p1.second-p2.second);
        int numberOfBoomerangs(vector<pair<int, int>>& points) {
            int sum=0;
            for(int i=0;i<points.size();i++){
                for(int j=0;j<points.size();j++) m[distance(points[i],points[j])]++;
                for(auto& x:m) if(x.second>1) sum+=x.second*(x.second-1);
            return sum;

Log in to reply

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