Skip to content

Commit 82eb694

Browse files
committed
Runtime: 506 ms (Top 5.92%) | Memory: 18.6 MB (Top 46.15%)
1 parent c7eeb88 commit 82eb694

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Runtime: 506 ms (Top 5.92%) | Memory: 18.6 MB (Top 46.15%)
2+
class Solution:
3+
"""
4+
1 <= rects.length <= 100
5+
rects[i].length == 4
6+
-10^9 <= ai < xi <= 10^9
7+
-10^9 <= bi < yi <= 10^9
8+
xi - ai <= 2000
9+
yi - bi <= 2000
10+
All the rectangles do not overlap.
11+
At most 10^4 calls will be made to pick.
12+
"""
13+
14+
def __init__(self, rects: List[List[int]]):
15+
self.rects = rects
16+
self.n_range = list(range(len(self.rects)))
17+
self.weights = [(x[2] - x[0] + 1) * (x[3] - x[1] + 1) for x in rects]
18+
19+
def pick(self) -> List[int]:
20+
rect = self.rects[choices(self.n_range, self.weights, k=1)[0]]
21+
return [randint(rect[0], rect[2]), randint(rect[1], rect[3])]
22+
23+
# Your Solution object will be instantiated and called as such:
24+
# obj = Solution(rects)
25+
# param_1 = obj.pick()

0 commit comments

Comments
 (0)