Line Reflection

Problem: Line Reflection

Just follow the hint.

Code in Python:

from collections import defaultdict

class Solution(object):
    def isReflected(self, points):
        """
        :type points: List[List[int]]
        :rtype: bool
        """
        if len(points) < 2: return True

        m = defaultdict(list)
        minX, maxX = None, None
        for point in points:
            if minX == None or point[0] < minX: minX = point[0]
            if maxX == None or point[0] > maxX: maxX = point[0]
            m[point[0]].append(point[1])

        line = minX + maxX
        for point in points:
            if point[0] == line: continue
            if point[1] not in m[line-point[0]]: return False
        return True

results matching ""

    No results matching ""