码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode1362

时间:2020-02-23 18:01:45      阅读:60      评论:0      收藏:0      [点我收藏+]

标签:com   lis   res   pytho   iso   div   参考   python   oat   

 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

标签:com   lis   res   pytho   iso   div   参考   python   oat   

原文地址:https://www.cnblogs.com/asenyang/p/12350697.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!