carloscn / carloscn/structstudy

leetcode492:构造矩形(construct-the-rectangle)

Open
#107 2 comments 0 reactions 1 assignee Claimed by @carloscn View on GitHub
Level-easy 一般问题 数组 查找
Dominant language
C
Stars
4
Forks
1
PR merge metrics
No merged PRs in 30d

Description

### 问题描述

作为一位web开发者, 懂得怎样去规划一个页面的尺寸是很重要的。 所以,现给定一个具体的矩形页面面积,你的任务是设计一个长度为 L 和宽度为 W 且满足以下要求的矩形的页面。要求:

你设计的矩形页面必须等于给定的目标面积。
宽度 W 不应大于长度 L ,换言之,要求 L >= W 。
长度 L 和宽度 W 之间的差距应当尽可能小。

返回一个 数组 [L, W],其中 L 和 W 是你按照顺序设计的网页的长度和宽度。

示例1:
输入: 4
输出: [2, 2]
解释: 目标面积是 4, 所有可能的构造方案有 [1,4], [2,2], [4,1]。
但是根据要求2,[1,4] 不符合要求; 根据要求3,[2,2] 比 [4,1] 更能符合要求. 所以输出长度 L 为 2, 宽度 W 为 2。

示例 2:
输入: area = 37
输出: [37,1]

示例 3:
输入: area = 122122
输出: [427,286]

提示:

1 <= area <= 107

来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/construct-the-rectangle

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.