1209. Construct the Rectangle

1209. Construct the Rectangle

class Solution {
public:
    /**
     * @param area: web pagea€?s area
     * @return: the length L and the width W of the web page you designed in sequence
     */
    vector<int> constructRectangle(int area) {
        // Write your code here
        int start = sqrt(area);
        while(area%start != 0 && start<area)
        {
            start ++;
        }
        vector<int> res;
        res.push_back(start);
        res.push_back(area/start);
        return res;
    }
};

原文地址:https://www.cnblogs.com/virgildevil/p/12155486.html

时间: 2024-07-31 22:22:34

1209. Construct the Rectangle的相关文章

LeetCode:492. Construct the Rectangle

1 package Today; 2 //LeetCode:492. Construct the Rectangle 3 /* 4 For a web developer, it is very important to know how to design a web page's size. 5 So, given a specific rectangular web page's area, your job by now is to design a rectangular web pa

LeetCode_492. Construct the Rectangle

492. Construct the Rectangle Easy For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W sat

492. 构造矩形 Construct the Rectangle

For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page's area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements: 1

492. Construct the Rectangle

For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page's area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements: 1

Construct the Rectangle

For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page's area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements: 1

LeetCode Construct the Rectangle

原题链接在这里:https://leetcode.com/problems/construct-the-rectangle/ 题目: For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page's area, your job by now is to design a rectangular web pag

492. Construct the Rectangle(LeetCode)

For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page's area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements: 1

[LeetCode&amp;Python] Problem 492. Construct the Rectangle

For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page's area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements: 1

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}; }