File tree 1 file changed +5
-6
lines changed
scripts/algorithms/D/Detect Squares
1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change
1
+ # Runtime: 658 ms (Top 42.61%) | Memory: 16 MB (Top 39.48%)
1
2
"""
2
3
Store every points and number of their appearance
3
4
Group the points by their x value
9
10
10
11
Use the decided side length to calculate p3 and p4, see if they are in the dict. If do, add product of their appearances.
11
12
12
- p3 p2 p3`
13
+ p3 p2 p3`
13
14
14
-
15
- p4 p1 p4`
15
+ p4 p1 p4`
16
16
17
17
Notice that p3 and p4 can be on both left side and right side of side (p2,p1)
18
18
@@ -48,11 +48,10 @@ def count(self, p1: List[int]) -> int:
48
48
p3 = (x1 + b ,y2 )
49
49
p4 = (x1 + b ,y1 )
50
50
if p3 in self .pts and p4 in self .pts :
51
- res += self .pts [p2 ]* self .pts [p3 ]* self .pts [p4 ]
51
+ res += self .pts [p2 ]* self .pts [p3 ]* self .pts [p4 ]
52
52
return res
53
53
54
-
55
54
# Your DetectSquares object will be instantiated and called as such:
56
55
# obj = DetectSquares()
57
56
# obj.add(point)
58
- # param_2 = obj.count(point)
57
+ # param_2 = obj.count(point)
You can’t perform that action at this time.
0 commit comments