Python Solution --- really simple


  • 0
    def isReflected(self, points):
        if not points:
            return True
        mid_point = self.determineMid(points)
        dic = collections.defaultdict(set)
        for x, y in points:
            dic[y].add(x)
        for y, xs in dic.iteritems():
            for x in xs:
                if 2*mid_point-x not in xs:
                    return False
        return True
                    
    def determineMid(self, points):
        y = points[0][1]
        min_x = max_x = points[0][0]
        for point in points:
            if point[1] == y:
                min_x = min(min_x, point[0])
                max_x = max(max_x, point[0])
        return (max_x + min_x)/2.0
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.