Skip to content

Commit a5bc529

Browse files
committed
feat(leetcode): add No.478
1 parent 85a06c9 commit a5bc529

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# https://leetcode.com/problems/generate-random-point-in-a-circle/description/
2+
#
3+
# algorithms
4+
# Medium (33.3%)
5+
# Total Accepted: 2.2k
6+
# Total Submissions: 6.6k
7+
# beats 65.29% of python submissions
8+
9+
10+
from random import uniform
11+
12+
13+
class Solution(object):
14+
15+
def __init__(self, radius, x_center, y_center):
16+
"""
17+
:type radius: float
18+
:type x_center: float
19+
:type y_center: float
20+
"""
21+
self.r = radius
22+
self.x = x_center
23+
self.y = y_center
24+
25+
def randPoint(self):
26+
"""
27+
:rtype: List[float]
28+
"""
29+
r = random.triangular(0, self.r, self.r)
30+
theta = random.uniform(-math.pi, math.pi)
31+
32+
return [self.x + r * math.cos(theta), self.y + r * math.sin(theta)]
33+
34+
35+
# Your Solution object will be instantiated and called as such:
36+
# obj = Solution(radius, x_center, y_center)
37+
# param_1 = obj.randPoint()

0 commit comments

Comments
 (0)