C++ n^2 solution using long long instead of pair<int, int>

• ``````/**
* Definition for a point.
* struct Point {
*     int x;
*     int y;
*     Point() : x(0), y(0) {}
*     Point(int a, int b) : x(a), y(b) {}
* };
*/
class Solution {
public:
int maxPoints(vector<Point>& points) {
int ret = min((int)points.size(), 1);
unordered_map<long long, int> hash;
for (int i = 0; i < points.size(); ++ i){
hash.clear();
for (int j = 0; j < points.size(); ++ j)
hash[getLong(points[j].x - points[i].x, points[j].y - points[i].y)] ++;
for (auto& p : hash)
ret = max(ret, p.second + (p.first == 0 ? 0 : hash[0]));
}
return ret;
}

private:
long long getLong(int x, int y){
int tmp = GCD(abs(x), abs(y));
x /= (tmp == 0 ? 1 : tmp);
y /= (tmp == 0 ? 1 : tmp);
return ((long long)((unsigned int)x) << 32) + (long long)((unsigned int)y);
}

int GCD(int a, int b) {
if (b == 0) return a;
return GCD(b, a%b);
}
};
``````

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