Skip to content

Commit bb01924

Browse files
authored
Create 2013-Detect-Squares.py
1 parent ca0e9c2 commit bb01924

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

2013-Detect-Squares.py

+19
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)