2013. Detect Squares (Medium) - TengnanYao/daily_leetcode GitHub Wiki
class DetectSquares:
def __init__(self):
self.h = Counter()
def add(self, point: List[int]) -> None:
self.h[point[0], point[1]] += 1
def count(self, point: List[int]) -> int:
result = 0
for x, y in self.h:
if abs(x - point[0]) == abs(y - point[1]) and x != point[0]:
result += self.h[x, y] * self.h[x, point[1]] * self.h[point[0], y]
return result
# Your DetectSquares object will be instantiated and called as such:
# obj = DetectSquares()
# obj.add(point)
# param_2 = obj.count(point)