您的位置:首页 > 其它

[LeetCode]492. Construct the Rectangle

2017-03-20 21:35 435 查看

[LeetCode]492. Construct the Rectangle

题目描述



思路

对输入的数据取平方根,然后递减遍历,第一个满足整除条件的数即为目标

代码

class Solution {
public:
vector<int> constructRectangle(int area) {
vector<int> res;
int sq = sqrt(area);
while (sq) {
if (area % sq == 0) {
res.push_back(area / sq);
res.push_back(sq);
break;
}
sq--;
}
return res;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: