File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1
1
2
+ const DetectSquares = function ( ) {
3
+ this . pts = [ ]
4
+ this . ptsCnt = { }
5
+ } ;
6
+
7
+ /**
8
+ * @param {number[] } point
9
+ * @return {void }
10
+ */
11
+ DetectSquares . prototype . add = function ( point ) {
12
+ this . pts . push ( point )
13
+ const key = `${ point [ 0 ] } ,${ point [ 1 ] } `
14
+ this . ptsCnt [ key ] = ( this . ptsCnt [ key ] || 0 ) + 1
15
+ } ;
16
+
17
+ /**
18
+ * @param {number[] } point
19
+ * @return {number }
20
+ */
21
+ DetectSquares . prototype . count = function ( point ) {
22
+ let res = 0
23
+ const [ px , py ] = point
24
+ for ( const [ x , y ] of this . pts ) {
25
+ if ( px === x || py === y || Math . abs ( px - x ) !== Math . abs ( py - y ) ) {
26
+ continue
27
+ }
28
+ res += ( this . ptsCnt [ `${ px } ,${ y } ` ] || 0 ) * ( this . ptsCnt [ `${ x } ,${ py } ` ] || 0 )
29
+ }
30
+
31
+ return res
32
+ } ;
33
+
34
+ /**
35
+ * Your DetectSquares object will be instantiated and called as such:
36
+ * var obj = new DetectSquares()
37
+ * obj.add(point)
38
+ * var param_2 = obj.count(point)
39
+ */
40
+
41
+
42
+ // another
43
+
2
44
var DetectSquares = function ( ) {
3
45
this . xMap = new Map ( ) ;
4
46
this . yMap = new Map ( ) ;
You can’t perform that action at this time.
0 commit comments