Skip to content

Commit 343e309

Browse files
committed
solve problem Construct The Rectangle
1 parent 721a6e4 commit 343e309

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ All solutions will be accepted!
100100
|453|[Minimum Moves To Equal Array Elements](https://leetcode-cn.com/problems/minimum-moves-to-equal-array-elements/description/)|[java/py/js](./algorithms/MinimumMovesToEqualArrayElements)|Easy|
101101
|661|[Image Smoother](https://leetcode-cn.com/problems/image-smoother/description/)|[java/py/js](./algorithms/ImageSmoother)|Easy|
102102
|598|[Range Addition II](https://leetcode-cn.com/problems/range-addition-ii/description/)|[java/py/js](./algorithms/RangeAdditionII)|Easy|
103+
|492|[Construct The Rectangle](https://leetcode-cn.com/problems/construct-the-rectangle/description/)|[java/py/js]|(./algorithms/ConstructTheRectangle)|Easy|
103104

104105
# Database
105106
|#|Title|Solution|Difficulty|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Construct The Rectangle
2+
This problem is easy to solve
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int[] constructRectangle(int area) {
3+
int W = (int) Math.sqrt(area),
4+
L = W;
5+
6+
while (W > 0) {
7+
L = area / W;
8+
if (area % W == 0) {
9+
break;
10+
}
11+
W -= 1;
12+
}
13+
return new int[]{L, W};
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number} area
3+
* @return {number[]}
4+
*/
5+
var constructRectangle = function(area) {
6+
let L = W = parseInt(Math.sqrt(area))
7+
8+
while (W > 0) {
9+
L = area / W
10+
if (area % W === 0) {
11+
break
12+
}
13+
W -= 1
14+
}
15+
return [L, W]
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution(object):
2+
def constructRectangle(self, area):
3+
"""
4+
:type area: int
5+
:rtype: List[int]
6+
"""
7+
L = W = int(math.sqrt(area))
8+
while W > 0:
9+
L = area / W
10+
mod = area % W
11+
if mod == 0:
12+
break
13+
W -= 1
14+
return [L, W]

0 commit comments

Comments
 (0)