//双指针
class Solution {
public:
vector<int> constructRectangle(int area)
{
vector<int> vec(2);
int sub_val = area;
int L = area, W = 1;
while (W<=L)
{
if (W * L == area && L - W <= sub_val) //L-W=chazhi 很重要,不单单是L- W<chazhi,例如area 为5时,就知道情况了,只有5,1,差值为4,只有<的话,就没结果了.
{
sub_val = L - W; //更改差值
vec[0] = L;
vec[1] = W;
++W, --L;
continue;
}
if (W * L < area)
{
++W;
}
if (W * L > area)
{
--L;
}
}
return vec;
}
};