1. 程式人生 > >492 Construct the Rectangle 構建矩形

492 Construct the Rectangle 構建矩形

details UC con rect csdn etc code SQ rec

詳見: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};
    }
};

參考:https://blog.csdn.net/liuchuo/article/details/54669517

492 Construct the Rectangle 構建矩形