The difference between length L and width W should be as small as possible. You need to output the length L and the width W of the web page you designed in sequence. Example: Input: 4 Output: [2, 2] Explanation:
L和W之差尽可能小 回到顶部 思路 为了满足条件,对面积开根号即可,但L和W为整数。因此先让W为面积开根号向下取整,再逐步自减,直到找到满足条件的L 回到顶部 代码 Java: publicclassSolution{publicint[] constructRectangle(intarea) {intwidth=(int) Math.sqrt(area);while(area % width !=0) { width--; ...
Can you solve this real interview question? Construct the Rectangle - A web developer needs 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 an
The web page's width and length you designed must be positive integers. classSolution(object):defconstructRectangle(self, area):""":type area: int :rtype: List[int]"""#greedy, from square areaforLinxrange(int(math.ceil(area**0.5)), area+1):ifarea % L ==0:return[L, area/L] 注意...
package leetcode import "math" func constructRectangle(area int) []int { ans := make([]int, 2) W := int(math.Sqrt(float64(area))) for W >= 1 { if area%W == 0 { ans[0], ans[1] = area/W, W break } W -= 1 } return ans } `` --- <div style="display: flex;jus...
leetcode 492. Construct the Rectangle Pick One 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......
class Solution { public int[] constructRectangle(int area) { int w=(int)Math.sqrt(area); int l = w; while(w>=1&&l<=area){ int t_area = w*l; if(t_area==area){ return new int[]{l,w}; } if(t_area > area){ w--; ...
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}; } }; 1. 2. 3. 4. 5. 6. ...
492. Construct the Rectangle 1. Description Given an integer representing the area of a rectangular. Find the length L and width W, and the difference between L and W should e as small as possible. 2. Solution Just do it. 3. Code......
LeetCode之Construct the Rectangle 简介:LeetCode之Construct the Rectangle 1、题目 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 ...