Formatted question description: https://leetcode.ca/all/356.html
356 Line Reflection Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given set of points. Example 1: Given points = [[1,1],[-1,1]], return true. Example 2: Given points = [[1,1],[-1,-1]], return false. Follow up: Could you do better than O(n2)? Hint: Find the smallest and largest x-value for all points. If there is a line then it should be at y = (minX + maxX) / 2. For each point, make sure that it has a reflected point in the opposite side.
The hints in the question are quite adequate, we just need to follow the hinted steps to solve the problem.
- First, we find the maximum and minimum values of the abscissa of all points, then the average of the two is the abscissa of the middle straight line,
- Then we traverse each point, and if we can find another point that is symmetrical in a straight line, we return true, otherwise we return false