最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網 會員登陸 & 注冊

LeetCode 1362. Closest Divisors

2023-08-14 12:41 作者:您是打尖兒還是住店呢  | 我要投稿

Given an integer?num, find the closest two integers in absolute difference whose product equals?num + 1?or?num + 2.

Return the two integers in any order.

?

Example 1:

Input: num = 8

Output: [3,3]

Explanation: For num + 1 = 9, the closest divisors are 3 & 3, for num + 2 = 10, the closest divisors are 2 & 5, hence 3 & 3 is chosen.

Example 2:

Input: num = 123

Output: [5,25]

Example 3:

Input: num = 999

Output: [40,25]

?

Constraints:

  • 1 <= num <= 10^9


Hide Hint 1

Find the divisors of n+1 and n+2.

Hide Hint 2

To find the divisors of a number, you only need to iterate to the square root of that number.


Runtime:?6 ms, faster than?82.52%?of?Java?online submissions for?Closest Divisors.

Memory Usage:?40.3 MB, less than?28.16%?of?Java?online submissions for?Closest Divisors.

--------------------------------------

依次遍歷即可:

下面是代碼:


LeetCode 1362. Closest Divisors的評論 (共 條)

分享到微博請遵守國家法律
宁化县| 临湘市| 西宁市| 松阳县| 观塘区| 岐山县| 吕梁市| 吉林市| 翁牛特旗| 厦门市| 兴安县| 吴堡县| 榆中县| 黄平县| 大足县| 平阴县| 安福县| 石家庄市| 二连浩特市| 瓦房店市| 遵化市| 黔东| 沈阳市| 衡水市| 绥棱县| 台东县| 阆中市| 贵德县| 台湾省| 遂昌县| 天全县| 岐山县| 上犹县| 罗城| 寻乌县| 卢氏县| 方山县| 巴马| 宝清县| 尚义县| 泊头市|