Construct the Rectangle LeetCode solution in Python

1
# Runtime: 39 ms (Top 86.68%) | Memory: 13.9 MB (Top 58.98%)
2
class Solution:
3
def constructRectangle(self, area: int):
4
y = Solution.mySqrt(area)
5
for i in range(y, 0, -1):
6
if not area % i:
7
return [int(area / i), i]
8

9
def mySqrt(x):
10
if x == 0:
11
return 0
12
n = x
13
count = 0
14
while True:
15
count += 1
16
root = 0.5 * (n + (x / n))
17
if abs(root - n) < 0.9:
18
break
19
n = root
20
return int(root)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0