leetcode1362

Posted AsenYang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode1362相关的知识,希望对你有一定的参考价值。

 1 class Solution:
 2     def closestDivisors(self, num: int) -> List[int]:
 3         d = float("inf")
 4         res = []
 5         for i in range(1, int((num + 1) ** 0.5 + 1)):
 6             if (num + 1) % i == 0:
 7                 if (num + 1) // i - i < d:
 8                     d = (num + 1) // i - i
 9                     res = [i, (num + 1) // i]
10         for i in range(1, int((num + 2) ** 0.5 + 1)):
11             if (num + 2) % i == 0:
12                 if (num + 2) // i - i < d:
13                     d = (num + 2) // i - i
14                     res = [i, (num + 2) // i]
15         return res

参考:https://leetcode.com/problems/closest-divisors/discuss/518058/python-3-easy-to-understand

以上是关于leetcode1362的主要内容,如果未能解决你的问题,请参考以下文章

Leetcode 1362. Closest Divisors

《算法零基础》第10讲:因子分解和枚举(部分)

leetcode_1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold_[二维前缀和](代码片段

CF-1362B. Johnny and His Hobbies

CF-1362B. Johnny and His Hobbies

CF-1362C. Johnny and Another Rating Drop