【leetcode】492. Construct the Rectangle

阅读 84

2022-07-12

problem

​​492. Construct the Rectangle​​

 solution1:

class Solution {
public:
vector<int> constructRectangle(int area) {
int r = sqrt(area);
while(area % r != 0) r--;
return {area/r, r};
}
};

 

solution2:

class Solution {
public:
vector<int> constructRectangle(int area) {
int r = 1;
for(int i=1; i*i <=area; i++)
{
if(area % i == 0) r = i;
}
return {area/r, r};
}
};

 

 

参考

1. ​​Leetcode_492. Construct the Rectangle​​;

2. ​​GrandYang​​;

精彩评论(0)

0 0 举报