Construct the Rectangle LeetCode solution in Java

1
class Solution {
2
public int[] constructRectangle(int area) {
3
int minDiff = Integer.MAX_VALUE;
4
int[] result = new int[2];
5

6
for (int w = 1; w * w <= area; w++) {
7
if (area % w == 0) {
8
int l = area / w;
9
int diff = l - w;
10
if (diff < minDiff) {
11
result[0] = l;
12
result[1] = w;
13
minDiff = diff;
14
}
15
}
16
}
17

18
return result;
19
}
20
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0