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. HDU 2682 Tree

    题目: There are N (2<=N<=600) cities,each has a value of happiness,we consider two cities A and ...

  2. 一篇文章让你深透理解cookie和session,附带分布式WEB系统redis共享session方案

    cookie和session有什么区别?这是一个很基础的知识点,大家可能都知道一个大概:cookie是存在客户端的,session是存储在服务端,cookie和session用来验证识别用户的登录状态 ...

  3. Robots.txt - 禁止爬虫

    robots.txt用于禁止网络爬虫访问网站指定目录.robots.txt的格式采用面向行的语法:空行.注释行(以#打头).规则行.规则行的格式为:Field: value.常见的规则行:User-A ...

  4. 邓_PPT

    如何拯救一份丑到爆的PPT? "小邓,这是我做的PPT,你优化优化,明天早上给我,上午客户来要用." 领导,你这是PPT嘛,明明就是word嘛. "小张啊,你看看我这个P ...

  5. linux_ssh

    什么是ssh? 配置文件位置:/etc/ssh/sshd_config 远程登录和为其他网络提供安全的加密数据传输协议,默认端口22,默认协议是SSH2 # 远程终端通过ssh连接服务器管理服务器 # ...

  6. Jquery实现选项卡效果

    <script type="text/javascript"> $(document).ready(function(){ $('.ct:gt(0)').hide(); ...

  7. EL表达式和JSTL核心标签库

    1 EL表达式 1.1 EL的概述 EL,全名为Expression Language. 主要作用: ①EL表达式主要用于替换jsp页面中的脚本表达式,以便于从各种类型的web域中检索java对象(某 ...

  8. js按位运算符及其妙用

    大多数语言都提供了按位运算符,恰当的使用按位运算符有时候会取得的很好的效果. 在我看来按位运算符应该有7个: 1.& 按位与 &是二元运算符,它以特定的方式的方式组合操作数中对应的位, ...

  9. PPT基础教程

    在当前演示文稿中增加新的幻灯片:快捷键>>ctrl+M  或者将鼠标定位到左侧窗格,然后按下回车键enter 母版??? 默认版式是"标题和文本"     右键 > ...

  10. Shell 批量复制文件名相近的文件到指定文件名中

    问题: 目录结构如下: test/ 2001.01.01/   2001.02.02/   2001.03.02/ 2001.01.03/    2001.02.04/   2001.03.05/ 2 ...