Line Reflection
Thoughts
Code
class Solution {
public boolean isReflected(int[][] points) {
int minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE;
Set<String> pts = new HashSet<>();
for (int[] point : points) {
minX = Math.min(minX, point[0]);
maxX = Math.max(maxX, point[0]);
pts.add(point[0] + "," + point[1]);
}
int sum = minX + maxX;
for (int[] point : points) {
int refX = sum - point[0];
if (pts.contains(refX + "," + point[1])) {
continue;
}
return false;
}
return true;
}
}Analysis
Last updated