Skip to content

Commit 97e019e

Browse files
authored
Update 2250-count-number-of-rectangles-containing-each-point.js
1 parent 55bde14 commit 97e019e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

2250-count-number-of-rectangles-containing-each-point.js

+36
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
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

0 commit comments

Comments
 (0)