We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ca0e9c2 commit bb01924Copy full SHA for bb01924
2013-Detect-Squares.py
@@ -0,0 +1,19 @@
1
+
2
+class DetectSquares:
3
4
+ def __init__(self):
5
+ self.ptsCount = defaultdict(int)
6
+ self.pts = []
7
8
+ def add(self, point: List[int]) -> None:
9
+ self.ptsCount[tuple(point)] += 1
10
+ self.pts.append(point)
11
12
+ def count(self, point: List[int]) -> int:
13
+ res = 0
14
+ px, py = point
15
+ for x, y in self.pts:
16
+ if (abs(py - y) != abs(px - x)) or x == px or y == py:
17
+ continue
18
+ res += self.ptsCount[(x, py)] * self.ptsCount[(px, y)]
19
+ return res
0 commit comments