-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path492.java
More file actions
36 lines (31 loc) · 970 Bytes
/
492.java
File metadata and controls
36 lines (31 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int[] constructRectangle(int area) {
int w = (int)Math.sqrt(area);
while (area%w!=0) w--;
return new int[]{area/w, w};
}
}
__________________________________________________________________________________________________
sample 32180 kb submission
class Solution {
public int[] constructRectangle(int area) {
int[] dim = new int[2];
int length = 1;
int width = (int) Math.sqrt(area);
while(width>=1)
{
length = area/width;
if(area%length==0)
{
break;
}
width--;
}
dim[0]=length;
dim[1]=width;
return dim;
}
}
__________________________________________________________________________________________________