-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathDetectSquares.cpp
More file actions
37 lines (31 loc) · 862 Bytes
/
Copy pathDetectSquares.cpp
File metadata and controls
37 lines (31 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class DetectSquares {
public:
unordered_map<vector<int>, int> ptsCount;
vector<vector<int>> points;
DetectSquares() {
}
void add(vector<int> point) {
ptsCount[point]++;
points.push_back(point);
}
int count(vector<int> point) {
int result = 0;
int px = point[0];
int py = point[1];
for(auto &ele: points) {
int x = ele[0];
int y = ele[1];
if(abs(py - y) != abs(px - x) or x == px or y == py) {
continue;
}
result += ptsCount[{x, py}] * ptsCount[{px, y}];
}
return result;
}
};
/**
* Your DetectSquares object will be instantiated and called as such:
* DetectSquares* obj = new DetectSquares();
* obj->add(point);
* int param_2 = obj->count(point);
*/