159ms C++ solution beats 98%


  • 0
    X
    class Solution {
    public:
        int numberOfBoomerangs(vector<pair<int, int>>& points) {
            int cnt=0,len=points.size();
            unordered_map<int,int>mp;
            for(int i=0;i<len;i++) {
                for(int j=0;j<len;j++) {
                    if(i==j) continue;
                    int distance = (points[i].first-points[j].first)*(points[i].first-points[j].first)
                                  +(points[i].second-points[j].second)*(points[i].second-points[j].second);
                    mp[distance]++;
                }
                for(auto & dp:mp) cnt+=dp.second*(dp.second-1);
                mp.clear();
            }
            return cnt;
        }
    };
    

Log in to reply
 

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