492 Construct the Rectangle

See: https://leetcode.com/problems/construct-the-rectangle/description/

C++:

class Solution {
public:
    vector<int> constructRectangle(int area) {
        int l=sqrt(area),w=sqrt(area);
        while(l*w!=area)
        {
            if(l*w<area)
            {
                ++l;
            }
            else
            {
                --w;
            }
        }
        return {l,w};
    }
};

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324605741&siteId=291194637