当前位置:网站首页>492. Construction rectangle
492. Construction rectangle
2022-07-02 06:00:00 【occasionally.】
1. Title Description
As a web developer , It's important to know how to plan the size of a page . therefore , Now give a specific rectangular page area , Your task is to design a length of L And the width is W A rectangular page that meets the following requirements . requirement :
① The rectangular page you design must be equal to the given target area .
② Width W Should not be greater than length L , In other words , requirement L >= W .
③ length L Width and width W The gap should be as small as possible .
Return to one Array [L, W], among L and W Is the length and width of the web pages you design in order .
Input : 4
Output : [2, 2]
explain : The target area is 4, All possible construction schemes are [1,4], [2,2], [4,1].
But on request 2,[1,4] Unqualified ; According to the requirements 3,[2,2] Than [4,1] Better meet the requirements . So the output length L by 2, Width W by 2.
2. Their thinking
The key is length L Width and width W The gap should be as small as possible , Obviously L=W Minimum time difference , So from sqrt(area) Start looking left , The first thing that can be divided by area is what you want W.
- python3
class Solution:
def constructRectangle(self, area: int) -> List[int]:
wide = int(sqrt(area))
while area % wide != 0:
wide -= 1
return [int(area/wide), wide]
- c++
class Solution {
public:
vector<int> constructRectangle(int area) {
int wide = (int)sqrt(area);
while (area % wide != 0){
wide--;
}
return vector<int>{
area/wide, wide};
}
}
边栏推荐
- The Hong Kong Stock Exchange learned from US stocks and pushed spac: the follow-up of many PE companies could not hide the embarrassment of the world's worst stock market
- STC8H8K系列汇编和C51实战——按键允许按键计数(利用下降沿中断控制)
- vite如何兼容低版本浏览器
- Stick to the big screen UI, finereport development diary
- 495.提莫攻击
- PHP read file (read the specified line containing a string in the file)
- Redis key value database [seckill]
- Lambda 表达式 和 方法引用
- Scheme and implementation of automatic renewal of token expiration
- STC8H8K系列汇编和C51实战——数码管显示ADC、按键串口回复按键号与ADC数值
猜你喜欢
![[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法](/img/25/73f11ab2711ed2cc9f20bc7f9116b6.png)
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法

ESP8266与STC8H8K单片机联动——天气时钟

深度学习分类网络--VGGNet

ZABBIX server trap command injection vulnerability (cve-2017-2824)

数理统计与机器学习

Vite打包后的dist不能直接在浏览器打开吗

Huawei Hongmeng OS, is it OK?

Cube magique infini "simple"

How to write good code - Defensive Programming Guide

Brain and cognitive neuroscience matlab psychoolbox cognitive science experimental design - experimental design 4
随机推荐
Page printing plug-in print js
How to change the IP address of computer mobile phone simulator
51单片机——ADC讲解(A/D转换、D/A转换)
如何使用MITMPROXy
Unity shader learning notes (3) URP rendering pipeline shaded PBR shader template (ASE optimized version)
PHP read file (read JSON file, convert to array)
数据回放伴侣Rviz+plotjuggler
php内类名称与类内方法名相同
PHP development and testing WebService (soap) -win
Web page user step-by-step operation guide plug-in driver js
1035 Password
《CGNF: CONDITIONAL GRAPH NEURAL FIELDS》阅读笔记
外部中断无法进入,删代码再还原就好......记录这个想不到的bug
[C language] screening method for prime numbers
php读文件(读取文件内含有某字符串的指定行)
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
【C语言】筛选法求素数
Gcnet: non - local Networks meet Squeeze excitation Networks and Beyond
Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)
Yyds dry inventory what is test driven development