public int[] constructRectangle(int area) {
int sqrt = (int)Math.sqrt(area);
int len =sqrt,wid=sqrt;
while(true){
int mul = len*wid;
if(mul==area)
return new int[]{len, wid};
else if(len>area || wid<1)
break;
else if(mul<area)
len ++;
else
wid--;
}
return new int[]{area, 1};
}
leetcode 492. Construct the Rectangle
最新推荐文章于 2021-04-25 19:02:01 发布