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 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的更多相关文章
- 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 ...
- 【leetcode】492. Construct the Rectangle
problem 492. Construct the Rectangle 参考 1. Leetcode_492. Construct the Rectangle; 完
- 【LeetCode】492. Construct the Rectangle 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 python解法 日期 题目地址:ht ...
- [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 ...
- [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 ...
- 492 Construct the Rectangle 构建矩形
详见:https://leetcode.com/problems/construct-the-rectangle/description/ C++: class Solution { public: ...
- 492. Construct the Rectangle
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- LeetCode——Construct the Rectangle
LeetCode--Construct the Rectangle Question For a web developer, it is very important to know how to ...
- leetcode面试准备: Maximal Rectangle
leetcode面试准备: Maximal Rectangle 1 题目 Given a 2D binary matrix filled with 0's and 1's, find the larg ...
随机推荐
- 久未更 ~ 三之 —— CardView简单记录
> > > > > 久未更 系列一:CardView 点击涟漪效果实现 //在 cardview 中 实现点击涟漪效果 android:clickable="t ...
- Navicat连接阿里云Mysql遇到的的坑
连上去那一刻,心态真是起飞了
- 两种方法上传本地文件到github
https://www.jianshu.com/p/c70ca3a02087 自从使用github以来,一直都是在github网站在线上传文件到仓库中,但是有时因为网络或者电脑的原因上传失败.最重要的 ...
- Putty(菩提)远程连接服务器教程听语音
Putty是一款优秀的免费串行接口连接软件,由于其绿色和性能深受业界好评,绿色是指putty使用便捷只需要将putty下载到电脑,无需安装,只需要在电脑上新建一个快捷方式就可以使用.出色的性能是指pu ...
- Java多线程异常处理
在java多线程程序中,所有线程都不允许抛出未捕获的checked exception,也就是说各个线程需要自己把自己的checked exception处理掉.这一点是通过java.lang.Run ...
- PowerDesigner设置null约束
在PDM的表属性的字段列表中每行最后的P,F,M中的M(Mandatory)打勾就可以了,这样在生成的SQL中会变成not NULL Mandatory:强制的,不知道是不是可以理解为必须赋值的
- shell 实现主板测试
初接触shell,只能需要用到什么功能现学先用了.本文总结一下完成测试程序当中遇到的技巧和问题. 01. 变量生存期的问题,在函数中的变量无法在其他地方使用,在函数中只能使用在函数前定义的全局变量: ...
- 进程间通信之利用CreateFilemapping()
这两天在复习进程间通信,复习一下记不住,复习一下记不住...就写个小博客献个丑,先来第一个内存映射 代码亲测通过 CreateFileMapping()的最后的一位用来做进程间通信 步骤: 1.Cre ...
- AI_深度学习为何兴起?
深度学习和神经网络,在此技术背后的理念,已经发展了好几十年了,为何现在流行起来了? 最直接因素: 将帮助你在自己的组织中,发现好机会,来应用这些东西 为什么深度学习这么厉害? x轴表示完成任务的数据数 ...
- Python简单爬虫Requests
首先添加库 附配环境变量:安装环境变量 cmd==> 输入指令: path=%path%;C:\Python(Python安装路径) 回车 python2.7版本可能没有pip的话可以先到www ...