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. UE4 内容示例网络同步Learn

    一, 1.1 Actor的复制 Actor中的Replicates ,为true时,服务器会把该Actor同步,显示在客户端中. 1.2 Switch Has Authority判断是客户端还是服务器 ...

  2. JAVA之JDBC的简单使用(Mysql)

    JDBC增删查改 昨天七七八八的关于Mysql的配置 和 基本使用也算是初步解决了,今天 抽空看了JAVA的JDBC(JAVA DATA BASE CONNECTION)我也不知道我全称拼写对对不对

  3. ThinkPHP5+小程序商城 网盘视频

    ThinkPHP5+小程序商城   网盘视频  有需要联系我  QQ:1844912514

  4. 织梦5.7DEDECMS标签大全

    1.关键描述调用标签: 2.路径调用标签: {dede:field name='templeturl'/} {dede:global.cfg_templets_skin/} 3.网站标题调用标签: d ...

  5. HTML <select>标签

    1.简单的下拉列表 <html> <body> <form> 名: <select name="firstname"> <op ...

  6. Java - 路线图

    java语言基础 基本语法 面向对象思想 mysql数据库基础 jdbc操作 java高级技术 java集合框架 多线程 网络编程 sql深入,索引,sql优化 javaweb servlet jsp ...

  7. 信号处理引发的cpu高

    背景知识: 1.tty 终端是一种字符型设备,它有多种类型,通常使用tty来简称各种类型的终端设备. tty指的是七个alt+crtl+F1~F7.tty1-tty6表示文字界面,可以用Ctrl+Al ...

  8. 搞个小项目吧,做一个ppt播放器

    先来两个参考链接,接下来再进行实战 http://www.geek-workshop.com/forum.php?mod=viewthread&tid=1137 http://www.geek ...

  9. Windows挂钩注入DLL

    注入DLL实现源码:HINSTANCE g_hInstDll = NULL; HHOOK g_hHook = NULL; DWORD g_dwThreadId = 0; #ifdef _MANAGED ...

  10. 【转】python入门指引

    http://matrix.42qu.com/10757179 前言 其实我也不知道python怎么入门,由我来写这个真的不是很合适.我学python是直接找了dive into python来看.然 ...