Skip to content

Commit 771b7f9

Browse files
authored
Create Construct the Rectangle.cpp
1 parent ccf1919 commit 771b7f9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Construct the Rectangle.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution {
2+
public:
3+
vector<int> constructRectangle(int area) {
4+
int j=1;
5+
int i=1;
6+
int l,w;
7+
int min=INT_MAX;
8+
for(;i;i++){
9+
if((j*i)==area){
10+
if(abs(i-j)<min){
11+
if(i>j){
12+
l=i;
13+
w=j;
14+
}
15+
else{
16+
l=j;
17+
w=i;
18+
}
19+
min=abs(i-j);
20+
}
21+
}
22+
if(i==area)
23+
{
24+
++j;
25+
i=1;
26+
}
27+
if(j==area)
28+
break;
29+
}
30+
vector<int>res;
31+
res.push_back(l);
32+
res.push_back(w);
33+
return res;
34+
}
35+
};

0 commit comments

Comments
 (0)