497. Random Point in Non-overlapping Rectangles
class Solution {
public:
vector<vector<int>> rects;
Solution(vector<vector<int>>& rects) {
this->rects = rects;
}
vector<int> pick() {
int num = 0;
vector<int> select;
for(auto rect : rects) {
int temp = (rect[2] - rect[0] + 1) * (rect[3] - rect[1] + 1);
num += temp;
if(rand() % num < temp) select = rect;
}
return {
rand() % (select[2] - select[0] + 1) + select[0], rand() % (select[3] - select[1] + 1) + select[1]};
}
};
/**
* Your Solution object will be instantiated and called as such:
* Solution* obj = new Solution(rects);
* vector<int> param_1 = obj->pick();
*/