C++ Beats 100% use 64-bit int to hash pair


  • 0
    S
    class Solution {
    public:
        bool isReflected(vector<pair<int, int>>& points) {
            int min_x = INT_MAX;
            int max_x = INT_MIN;
            
            unordered_set<int64_t> s;
            
            for (auto p: points) {
                min_x = min(min_x, p.first);
                max_x = max(max_x, p.first);
                int64_t t1 = p.first;
                int64_t t2 = p.second;
                int64_t r = t1 << 32 + t2;
                s.insert(r);
            }
    
            int64_t z = min_x+max_x;
            
            for (auto p: points) {
                int64_t comp_x = z - p.first;
                int64_t comp_y = p.second;
                int64_t h = comp_x << 32 + comp_y;
                if (s.find(h) == s.end()) return false;   
            }
            
            return true;
        }
    };
    

Log in to reply
 

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