Skip to content

Commit

Permalink
feat: add python solution to lc problem: No.0478 (#1883)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrhitik authored Oct 26, 2023
1 parent 687217d commit c9c6625
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
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]

0 comments on commit c9c6625

Please sign in to comment.