Count Number of Rectangles Containing Each Point LeetCode solution in C++

1
class Solution {
2
public:
3
vector<int> countRectangles(vector<vector<int>> &rectangles, vector<vector<int>> &points) {
4
int i, count, ind, x, y, n = rectangles.size();
5

6
vector<int> ans;
7
vector<vector<int>> heights(101);
8

9
for (auto rect : rectangles) heights[rect[1]].push_back(rect[0]);
10

11
for (i = 0; i < 101; i++) sort(heights[i].begin(), heights[i].end());
12

13
for (auto point : points) {
14
count = 0;
15
x = point[0];
16
y = point[1];
17
for (i = y; i < 101; i++) {
18
ind = lower_bound(heights[i].begin(), heights[i].end(), x) - heights[i].begin();
19
count += (heights[i].size() - ind);
20
}
21
ans.push_back(count);
22
}
23
return ans;
24
}
25
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0