题目链接:https://leetcode-cn.com/problems/construct-the-rectangle/
题目如下:
class Solution {
public:
vector<int> constructRectangle(int area) {
vector<int> result;
if(area==0) return result;
int gap=INT_MAX,L1=-1,W1=-1;
for(int W=1;W<=(int)sqrt(area);W++){
if(area%W==0) {
int L=area/W;
if(L-W<gap){gap=L-W;L1=L;W1=W;}
}
}
result.push_back(L1);
result.push_back(W1);
return result;
}
};