Skip to content

Commit d6a520b

Browse files
committed
2022-06-04 update: added "Construct the Rectangle"
1 parent db784db commit d6a520b

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

0 commit comments

Comments
 (0)