c++ with normal array operation 36ms


  • 0
    T
    class Solution {
    public:
        bool isReflected(vector<pair<int, int>>& points) {
            
            unordered_map<int, vector<double>> pts;
            double midp = .0, minv = INT_MAX, maxv = INT_MIN;
            for (auto &p:points){ 
                pts[p.second].push_back(p.first);
                minv = min(minv, (double)p.first), maxv = max(maxv, (double)p.first);
            }
            midp = (minv+maxv)/2.0;
            
            for (auto &p:pts) {
                unordered_set<double> dist;
                for (int i:p.second) {
                    dist.insert(i-midp);
                }
                while (!dist.empty()) {
                    double d = *dist.begin();
                    if (dist.find(-d) != dist.end()) {
                        dist.erase(d); dist.erase(-d);
                    }
                    else return false;
                }
            }
            return true;
        }
    };
    

  • 0
    W

    This is not correct. It will not pass the follow case for example:
    [[0,1],[3,1],[4,1],[8,1],[10,1]]

    which should return false

    The test cases in this problem are very weak.


  • 0
    T

    @wrbuaa2005 yeah you are right, thanks for pointing it out! I have updated the post, the run time is 45ms now


Log in to reply
 

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