1 public class Solution { 2 public boolean isReflected(int[][] points) { 3 if (points.length == 0) { 4 return true; 5 } 6 Set<String> record = new HashSet<>(); 7 int maxX = Integer.MIN_VALUE; 8 int minX = Integer.MAX_VALUE; 9 for (int[] point : points) { 10 maxX = Math.max(maxX, point[0]); 11 minX = Math.min(minX, point[0]); 12 record.add(point[0] + ":" + point[1]); 13 } 14 15 for (int[] point : points) { 16 if (!record.contains((maxX + minX - point[0]) + ":" + point[1])) { 17 return false; 18 } 19 } 20 return true; 21 } 22 }
Another solution is sort all the points and create another reflected points array. Sort again, then they should be same.