forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path356.Line Reflection.cpp
More file actions
38 lines (33 loc) · 854 Bytes
/
Copy path356.Line Reflection.cpp
File metadata and controls
38 lines (33 loc) · 854 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
38
class Solution {
public:
bool isReflected(vector<pair<int, int>>& points)
{
int N=points.size();
if (N==0) return true;
unordered_map<int,set<int>>Map;
unordered_set<int>Set;
for (int i=0; i<N; i++)
{
Map[points[i].second].insert(points[i].first);
Set.insert(points[i].first);
}
float x0=0;
for (auto a:Set)
x0+=a;
x0=x0/Set.size();
for (auto a:Map)
{
vector<int>q(a.second.begin(),a.second.end());
int i=0;
int j=q.size()-1;
while (i<=j)
{
if (q[i]+q[j]!=x0*2)
return false;
i++;
j--;
}
}
return true;
}
};