File tree 5 files changed +48
-0
lines changed
algorithms/ConstructTheRectangle
5 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ All solutions will be accepted!
100
100
| 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|
101
101
| 661| [ Image Smoother] ( https://leetcode-cn.com/problems/image-smoother/description/ ) | [ java/py/js] ( ./algorithms/ImageSmoother ) | Easy|
102
102
| 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|
103
104
104
105
# Database
105
106
| #| Title| Solution| Difficulty|
Original file line number Diff line number Diff line change
1
+ # Construct The Rectangle
2
+ This problem is easy to solve
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
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 ]
You can’t perform that action at this time.
0 commit comments