File tree 2 files changed +38
-0
lines changed
main/java/com/smlnskgmail/jaman/leetcodejava/easy
test/java/com/smlnskgmail/jaman/leetcodejava/easy
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .smlnskgmail .jaman .leetcodejava .easy ;
2
+
3
+ // https://leetcode.com/problems/construct-the-rectangle/
4
+ public class ConstructTheRectangle {
5
+
6
+ private final int input ;
7
+
8
+ public ConstructTheRectangle (int input ) {
9
+ this .input = input ;
10
+ }
11
+
12
+ public int [] solution () {
13
+ for (int i = (int ) Math .sqrt (input ); i >= 1 ; i --) {
14
+ if (input % i == 0 ) {
15
+ return new int []{input / i , i };
16
+ }
17
+ }
18
+ return null ;
19
+ }
20
+
21
+ }
Original file line number Diff line number Diff line change
1
+ package com .smlnskgmail .jaman .leetcodejava .easy ;
2
+
3
+ import org .junit .Test ;
4
+
5
+ import static org .junit .Assert .assertArrayEquals ;
6
+
7
+ public class ConstructTheRectangleTest {
8
+
9
+ @ Test
10
+ public void defaultTest () {
11
+ assertArrayEquals (
12
+ new int []{2 , 2 },
13
+ new ConstructTheRectangle (4 ).solution ()
14
+ );
15
+ }
16
+
17
+ }
You can’t perform that action at this time.
0 commit comments