【leetcode】492. Construct the Rectangle

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;

原文地址:https://www.cnblogs.com/happyamyhope/p/10623330.html