140ms C++ solution -- O(n^2), of course.


  • 0
    W
        int numberOfBoomerangs(const vector<pair<int, int>>& points) {
            short len{points.size()};
            unordered_map<int, int> mymap;
            int total{};
            const pair<int, int> *data{points.data()};
            
            for (short ii = 0; ii < len; ++ii) {
                for (short jj = 0; jj < len; ++jj) {
                    if (ii == jj)
                        continue;
    
                    total += mymap[((data + ii)->first - (data + jj)->first)*((data + ii)->first - (data + jj)->first) + \
                                   ((data + ii)->second - (data + jj)->second)*((data + ii)->second - (data + jj)->second)]++;
                }
                mymap.clear();
            }
            
            return 2*total;
        }
    

Log in to reply
 

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