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

思路就是先找sqrt, 然后依次往下减, 一旦可以被整除, 就输出.

Code

class Solution:
def constructRectangle(self, area):
width = int(math.sqrt(area))
while area%width:
width -= 1
return area//width, width

[LeetCode] 492. Construct the Rectangle_Easy tag: Math的更多相关文章

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

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

  3. [LeetCode] 598. Range Addition II_Easy tag: Math

    做个基本思路可以用 brute force, 但时间复杂度较高. 因为起始值都为0, 所以肯定是左上角的重合的最小的长方形就是结果, 所以我们求x, y 的最小值, 最后返回x*y. Code    ...

  4. [LeetCode] 367. Valid Perfect Square_Easy tag:Math

    Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...

  5. [LeetCode] 172. Factorial Trailing Zeroes_Easy tag: Math

    Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...

  6. [LeetCode] 728. Self Dividing Numbers_Easy tag: Math

    A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is ...

  7. [LeetCode] 106. Construct Binary Tree from Postorder and Inorder Traversal_Medium tag: Tree Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  8. 【leetcode】492. Construct the Rectangle

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

  9. (二叉树 递归) leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

随机推荐

  1. maven assembly plugin使用

    使用场景 在使用maven来管理项目时,项目除了web项目,还有可能为控制台程序,一般用于开发一些后台服务的程序.最近在工作中也遇到了这种场景,使用quartz开发一个任务调度程序.程序中依赖很多ja ...

  2. Linux上强制踢出其他正在登录的用户

    一.查看当前在线用户有几个 w命令 [root@pa1 nginx]#w 13:36:00 up 79 days, 23:50, 3 users, load average: 0.10, 0.07, ...

  3. Django----认证系统和auth模块

    COOKIE 与 SESSION 概念 cookie不属于http协议范围,由于http协议无法保持状态,但实际情况,我们却又需要“保持状态”,因此cookie就是在这样一个场景下诞生. cookie ...

  4. 不同的GCD算法

    分类: C语言程序2014-10-08 15:10 28人阅读 评论(0) 收藏 举报 gcdC语言程序位运算 早在公元前300年左右,欧几里得就在他的著作<几何原本>中给出了高效的解法- ...

  5. Linux系统下公式编辑器KLatexFormula

    方法1:源码安装 https://blog.csdn.net/ouening/article/details/79008636 方法2:通过apt-get 安装 首先安装libqt4-sql-sqli ...

  6. jdbc --- javabean

    第一部分: javaBean 类  要和数据库表的字段一一对应 package com.ljs.bean; public class UserBean { private int id; privat ...

  7. iOS 通知名的通用定义方法

    开发当中用到通知,通知的定义必须要有一个字符串标识通知的名字.一般可以直接写一个字符串,在通知创建和监听的时候直接写这个字符串. 但这样做非常不好,随手创建写代码当时很舒服,但是后来维护的时候发现通知 ...

  8. centos6.5设置key登录

    1.ssh-keygen -t rsa  一路回车,当然可以设置key密码 2.cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_key ...

  9. [daily][archlinux] 本地字符乱码, 无法显示中文

    一: 突然有一天,Konsole里边看见的中文文件名的文件,就变成了乱码.thunderbird存到本地的附件,文件名也变成了乱码. 在X下查看locale,内容如下: 手动设置了之后也不对. 但是在 ...

  10. 20165317JAVA实验二-面向对象程序设计

    JAVA实验二-面向对象程序设计 提交点一 参考Intellj IDEA 简易教程-单元测试完成单元测试的学习 在IDEA中建立名为MyUtil5317的project,并在其src文件夹中创建名为M ...