File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[][] } rectangles
3+ * @param {number[][] } points
4+ * @return {number[] }
5+ */
6+ const countRectangles = function ( rectangles , points ) {
7+ const rect = rectangles
8+ const matrix = Array . from ( { length : 101 } , ( ) => [ ] )
9+ for ( const [ x , y ] of rect ) {
10+ matrix [ y ] . push ( x )
11+ }
12+ for ( const row of matrix ) row . sort ( ( a , b ) => a - b )
13+ const res = [ ]
14+
15+ for ( const [ x , y ] of points ) {
16+
17+ let cnt = 0
18+ for ( let i = y ; i <= 100 ; i ++ ) {
19+ const arr = matrix [ i ] , n = arr . length
20+ let l = 0 , r = n
21+ while ( l < r ) {
22+ const mid = l + Math . floor ( ( r - l ) / 2 )
23+ if ( mid === n || arr [ mid ] >= x ) r = mid
24+ else l = mid + 1
25+ }
26+ cnt += n - l
27+ }
28+
29+ res . push ( cnt )
30+ }
31+
32+ return res
33+ } ;
34+
35+ // another
36+
137/**
238 * @param {number[][] } rectangles
339 * @param {number[][] } points
You can’t perform that action at this time.
0 commit comments