Skip to content

Commit 7487cc9

Browse files
Create construct-the-rectangle.java
1 parent 8589f3e commit 7487cc9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

construct-the-rectangle.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class Solution {
2+
public int[] constructRectangle(int area) {
3+
int n = (int) Math.sqrt(area);
4+
for (int i = n; i > 0; i--) {
5+
if (area % i == 0) return new int[] {i, area/i};
6+
}
7+
return new int[] {1, area};
8+
}
9+
}

0 commit comments

Comments
 (0)