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. qt 调用zlib压缩与解压缩功能

    Zlib是一种免费且通用的压缩库,由于Zlib压缩效果比LZW好,而且解压缩速度快,更重要的是商业软件中使用Zlib不需要缴纳版权费,所以很多游戏都使用Zlib压缩资源文件. Zlib是由Jean-l ...

  2. Java中的equals和==的差别 以及Java中等价性和同一性的讨论

    ==对基本数据类型比较的是值,对引用类型比较的是地址 equals()比较的是对象的数据的引用 等价性原理: 自反性    x.equals(x)为true 对称性    x.equals(y) 为t ...

  3. U帮忙U盘启动盘制作

    第一步:制作U盘启动盘前的软.硬件准备 1.准备一个U盘或内存卡(尽量使用2G以上的) 2.进入 U帮忙官网 下载最新版U盘启动盘制作工具! 3.搜索并下载ghost版系统文件存放到电脑中. 第二步: ...

  4. json 2017-04-21 10 17

    jo := SO(); jo.S['tttt'] := 'tttt'; TbSendedTidJson['jo'] := jo; ja := TbSendedTidJson['jo'];//取出来后, ...

  5. Saiku缓存处理(七)

    Saiku缓存处理方案 Saiku默认是从缓存中读取数据的(如果缓存中有数据的话),所以用户看到的数据不一定是最新的,如果需要看到最新的的数据需要手动刷新数据或者更改配置信息. Saiku获取实时数据 ...

  6. 常见的SQLALCHEMY列类型

    常见的SQLALCHEMY列类型.配置选项和关系选项   类型名称    python类型    描述 Integer int 常规整形,通常为32位 SmallInteger    int 短整形, ...

  7. X86汇编语言实现的贪吃蛇游戏

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  8. 初始JSP

    什么是JSP 1.JSP(Java Server Pages):在HTML中嵌入Java脚本代码 静态内容是JSP页面中的静态文本,其基本是HTML文本,与Java和JSP语法无关. 例子: 运行结果 ...

  9. SQL-29 使用join查询方式找出没有分类的电影id以及名称

    题目描述 film表 字段 说明 film_id 电影id title 电影名称 description 电影描述信息 CREATE TABLE IF NOT EXISTS film ( film_i ...

  10. 7 Serial Configuration 理解 (一)

    reference :  ug470- 7 series config.pdf 7系列器件有5种配置接口,每种配置接口对应一种或者多种配置模式和总线位宽.配置时序相对于引脚的CCLK,即使在内部产生C ...