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.

Note:

  1. The given area won't exceed 10,000,000 and is a positive integer
  2. The web page's width and length you designed must be positive integers.
 
 
class Solution(object):
def constructRectangle(self, area):
"""
:type area: int
:rtype: List[int]
"""
min1=area-1
ans=[area,1]
i=2
while i*i<=area:
if area%i==0:
if area/i-i<min1:
min1=area/i-i
ans[0]=area/i
ans[1]=i
i+=1
return ans

  

[LeetCode&Python] Problem 492. Construct the Rectangle的更多相关文章

  1. [LeetCode&Python] Problem 427. Construct Quad Tree

    We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or ...

  2. [LeetCode&Python] Problem 606. Construct String from Binary Tree

    You need to construct a string consists of parenthesis and integers from a binary tree with the preo ...

  3. 【leetcode】492. Construct the Rectangle

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

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

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

  5. LeetCode - 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 ...

  6. [LeetCode&Python] Problem 836. Rectangle Overlap

    A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...

  7. 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 ...

  8. [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...

  9. [LeetCode&Python] Problem 387. First Unique Character in a String

    Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...

随机推荐

  1. 【转】C# string数组转int数组

    //字符串数组(源数组) string[] sNums = new[] {"1", "2"}; //整型数组(目标数组) int[] iNums; //转换方法 ...

  2. python3+ftplib实现ftp客户端

    一.程序说明 1.1 程序实现关键点 python实现ftp客户端,主要会遇到以下四个问题: 第一个问题是使用什么包实现----我们这里是使用标准库中的ftplib 第二个问题是怎么连接登录ftp服务 ...

  3. js实现页面与页面之间传值的几种方法优劣

    1. cookie 传值, 缺点: cookie储存是需要服务器支持的,本地直接运行静态文件是实现不了的 <script> //添加 cookie function cp_add_cook ...

  4. 每天进步一点点out1

    1● attend ətend   2● infant əfənd  

  5. mac CodeIgniter和EasyWeChat 开发微信公众号

    mac 安装 Composer //composer安装成功 curl -sS https://getcomposer.org/installer | php //将composer.phar移动到 ...

  6. 【Jenkins】Jenkins安装修改默认路径和端口的方法

    一.修改默认的jenkins安装路径 因为jenkins默认安装在c盘 C:\Users\Administrator\.jenkins下,那怎样将安装路径修改至d盘呢? 新建一个系统变量:JENKIN ...

  7. asp.net中javascript与后台c#交互

    asp.net中javascript与后台c#交互 作者:熊猫大叔 字体:[增加 减小] 类型:转载 时间:2015-10-23我要评论,出处:http://www.jb51.net/article/ ...

  8. bzoj4278

    题解: 把第一个串放好,加一个oo 然后把第二个串倒序放进来 然后就是http://www.cnblogs.com/xuanyiming/p/8510231.html这一题了 代码: #include ...

  9. 反片语 UVA 156

    //该单词不能通过字母重排,得到输入文本中的另外一个单词.在判断是否满足条件时,字母部分大小写 #include<iostream> #include<vector> #inc ...

  10. 数据库-->表操作

    一.MySQL存储引擎 # InnoDB MySql 5.6 版本默认的存储引擎.InnoDB 是一个事务安全的存储引擎,它具备提交.回滚以及崩溃恢复的功能以保护用户数据.InnoDB 的行级别锁定以 ...