Skip to content

Commit c800761

Browse files
committed
feat: add typescript solution to lc problem: No.2250
No.2250.Count Number of Rectangles Containing Each Point
1 parent 3ae1177 commit c800761

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

solution/2200-2299/2250.Count Number of Rectangles Containing Each Point/README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,35 @@
8585
### **TypeScript**
8686

8787
```ts
88-
88+
function countRectangles(rectangles: number[][], points: number[][]): number[] {
89+
const n = 101;
90+
let ymap = Array.from({ length: n }, v => []);
91+
for (let [x, y] of rectangles) {
92+
ymap[y].push(x);
93+
}
94+
for (let nums of ymap) {
95+
nums.sort((a, b) => a - b);
96+
}
97+
let ans = [];
98+
for (let [x, y] of points) {
99+
let count = 0;
100+
for (let h = y; h < n; h++) {
101+
const nums = ymap[h];
102+
let left = 0, right = nums.length;
103+
while (left < right) {
104+
let mid = (left + right) >> 1;
105+
if (x > nums[mid]) {
106+
left = mid + 1;
107+
} else {
108+
right = mid;
109+
}
110+
}
111+
count += (nums.length - right);
112+
}
113+
ans.push(count);
114+
}
115+
return ans;
116+
};
89117
```
90118

91119
### **...**

solution/2200-2299/2250.Count Number of Rectangles Containing Each Point/README_EN.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,35 @@ Therefore, we return [1, 3].
7272
### **TypeScript**
7373

7474
```ts
75-
75+
function countRectangles(rectangles: number[][], points: number[][]): number[] {
76+
const n = 101;
77+
let ymap = Array.from({ length: n }, v => []);
78+
for (let [x, y] of rectangles) {
79+
ymap[y].push(x);
80+
}
81+
for (let nums of ymap) {
82+
nums.sort((a, b) => a - b);
83+
}
84+
let ans = [];
85+
for (let [x, y] of points) {
86+
let count = 0;
87+
for (let h = y; h < n; h++) {
88+
const nums = ymap[h];
89+
let left = 0, right = nums.length;
90+
while (left < right) {
91+
let mid = (left + right) >> 1;
92+
if (x > nums[mid]) {
93+
left = mid + 1;
94+
} else {
95+
right = mid;
96+
}
97+
}
98+
count += (nums.length - right);
99+
}
100+
ans.push(count);
101+
}
102+
return ans;
103+
};
76104
```
77105

78106
### **...**
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function countRectangles(rectangles: number[][], points: number[][]): number[] {
2+
const n = 101;
3+
let ymap = Array.from({ length: n }, v => []);
4+
for (let [x, y] of rectangles) {
5+
ymap[y].push(x);
6+
}
7+
for (let nums of ymap) {
8+
nums.sort((a, b) => a - b);
9+
}
10+
let ans = [];
11+
for (let [x, y] of points) {
12+
let count = 0;
13+
for (let h = y; h < n; h++) {
14+
const nums = ymap[h];
15+
let left = 0, right = nums.length;
16+
while (left < right) {
17+
let mid = (left + right) >> 1;
18+
if (x > nums[mid]) {
19+
left = mid + 1;
20+
} else {
21+
right = mid;
22+
}
23+
}
24+
count += (nums.length - right);
25+
}
26+
ans.push(count);
27+
}
28+
return ans;
29+
};

0 commit comments

Comments
 (0)