492 Construct the Rectangle 构建矩形

详见: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

posted on 2018-04-21 22:37  lina2014  阅读(107)  评论(0编辑  收藏  举报

导航