0
点赞
收藏
分享

微信扫一扫

【leetcode】492. Construct the Rectangle

624c95384278 2022-07-12 阅读 84

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 条评论