forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.ts
30 lines (30 loc) · 845 Bytes
/
Solution.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function countRectangles(rectangles: number[][], points: number[][]): number[] {
const n = 101;
let ymap = Array.from({ length: n }, v => []);
for (let [x, y] of rectangles) {
ymap[y].push(x);
}
for (let nums of ymap) {
nums.sort((a, b) => a - b);
}
let ans = [];
for (let [x, y] of points) {
let count = 0;
for (let h = y; h < n; h++) {
const nums = ymap[h];
let left = 0,
right = nums.length;
while (left < right) {
let mid = (left + right) >> 1;
if (x > nums[mid]) {
left = mid + 1;
} else {
right = mid;
}
}
count += nums.length - right;
}
ans.push(count);
}
return ans;
}