Skip to content

Solution for 478. #1883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ solution.randPoint ();//返回[0.36572,0.17248]</pre>
<!-- 这里可写当前语言的特殊实现逻辑 -->

```python
class Solution:
def __init__(self, radius: float, x_center: float, y_center: float):
self.radius = radius
self.x_center = x_center
self.y_center = y_center

def randPoint(self) -> List[float]:
length = math.sqrt(random.uniform(0, self.radius**2))
degree = random.uniform(0, 1) * 2 * math.pi
x = self.x_center + length * math.cos(degree)
y = self.y_center + length * math.sin(degree)
return [x, y]

```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ solution.randPoint(); // return [0.36572, 0.17248]
### **Python3**

```python
class Solution:
def __init__(self, radius: float, x_center: float, y_center: float):
self.radius = radius
self.x_center = x_center
self.y_center = y_center

def randPoint(self) -> List[float]:
length = math.sqrt(random.uniform(0, self.radius**2))
degree = random.uniform(0, 1) * 2 * math.pi
x = self.x_center + length * math.cos(degree)
y = self.y_center + length * math.sin(degree)
return [x, y]

```

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def __init__(self, radius: float, x_center: float, y_center: float):
self.radius = radius
self.x_center = x_center
self.y_center = y_center

def randPoint(self) -> List[float]:
length = math.sqrt(random.uniform(0, self.radius**2))
degree = random.uniform(0, 1) * 2 * math.pi
x = self.x_center + length * math.cos(degree)
y = self.y_center + length * math.sin(degree)
return [x, y]