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. The area of the rectangular web page you designed must equal to the given target area.

2. The width W should not be larger than the length L, which means L >= W.

3. 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: The target area is 4, and all the possible ways to construct it are [1,4], [2,2], [4,1].
But according to requirement 2, [1,4] is illegal; according to requirement 3, [4,1] is not optimal compared to [2,2]. So the
 length L is 2, and the width W is 2.
import java.lang.Math;
public class Solution {
public int[] constructRectangle(int area) {
int left = (int)Math.sqrt(area);
while ((area % left) != 0) left --;
return new int[]{area/left, left};
}
}

LeetCode - 492. Construct the Rectangle的更多相关文章

  1. LeetCode: 492 Construct the Rectangle(easy)

    题目: or a web developer, it is very important to know how to design a web page's size. So, given a sp ...

  2. 【leetcode】492. Construct the Rectangle

    problem 492. Construct the Rectangle 参考 1. Leetcode_492. Construct the Rectangle; 完

  3. 【LeetCode】492. Construct the Rectangle 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 python解法 日期 题目地址:ht ...

  4. [LeetCode&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 speci ...

  5. [LeetCode] 492. Construct the Rectangle_Easy tag: Math

    For a web developer, it is very important to know how to design a web page's size. So, given a speci ...

  6. 492 Construct the Rectangle 构建矩形

    详见:https://leetcode.com/problems/construct-the-rectangle/description/ C++: class Solution { public: ...

  7. 492. Construct the Rectangle

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  8. LeetCode——Construct the Rectangle

    LeetCode--Construct the Rectangle Question For a web developer, it is very important to know how to ...

  9. leetcode面试准备: Maximal Rectangle

    leetcode面试准备: Maximal Rectangle 1 题目 Given a 2D binary matrix filled with 0's and 1's, find the larg ...

随机推荐

  1. mac android studio 出现 Error: SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

      Error: SDK location not found. Define location with sdk.dir in the local.properties file or with a ...

  2. Vuethink正确安装过程

    1.      下载项目vuethink,本例将项目放置website文件下. 2.      后台搭建 本地建站–>以phpstudy为例 1)      新建站点域名 <Virtual ...

  3. DEDECMS首页调用图片集里的多张图片

    本文给大家分享的是织梦系统中首页调用图片集里的多张图片的方法,有相同需要的小伙伴可以参考下. 先找到include/common.inc.php文件,把下面代码贴进去(我贴的是我网站上的,具体可根据需 ...

  4. 火狐浏览器怎么查看页面加载了那些js文件,那系js文件有作用

    方法一: 右击查看原代码,点击js链接如果能够看到文件内容,证明加载成功 方法二: 按F12键,如果控制台没有加载错误,证明加载成功:

  5. 修改国内yum源

    yum的源配置文件名为:CentOS-Base.repo 一般情况是在/etc/yum.repos.d目录下有CentOS-Base.repo 备份CentOS-Base.repo文件 打开这个网站h ...

  6. Java线程-异常处理

    在Java多线程程序中,所有线程都不允许抛出未捕获的checked exception,也就是说各个线程需要自己把自己的checked exception处理掉.这一点是通过java.lang.Run ...

  7. background是什么样式?

    background是什么样式? 给标签添加背景图片 分为: background: url("图片路径");    #添加图片 background-position: xpx ...

  8. js 数组与对象的区别

    学习javascript的时候,我曾经一度搞不清楚”数组”(array)和”对象”(object)的根本区别在哪里,两者都可以用来表示数据的集合.   比如有一个数组a=[1,2,3,4],还有一个对 ...

  9. Servlet--ServletConfig接口,GenericServlet类

    ServletConfig接口 定义:public interface ServletConfig 这个接口定义了一个对象, 通过这个对象, Servlet 引擎配置一个 Servlet 并且允许 S ...

  10. awk说明书(转)

    ref:http://blog.chinaunix.net/uid-429659-id-122573.html awk使用手册 作者:awk使用手册什么是awk? 你可能对UNIX比较熟悉,但你可能对 ...