堆相关题目-python
栈&队列&哈希表&堆-python https://blog.csdn.net/qq_19446965/article/details/102982047 1、丑数 II 编写一个程序,找出第 n 个丑数。 丑数就是只包含质因数 2, 3, 5 的正整数。 示例: 输入: n = 10 输出: 12 解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 是前 10 个丑数。 说明: 1 是丑数。 n 不超过1690。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/ugly-number-ii 先回忆一下《丑数 I》 编写一个程序判断给定的数是否为丑数。 https://leetcode-cn.com/problems/ugly-number-ii/ class Solution(object): def isUgly(self, num): """ :type num: int :rtype: bool """ if num <= 0: return False if num == 1: return True while num >= 2 and num % 2 == 0: num /= 2 while num >= 3 and num % 3 == 0: num /= 3 while num >= 5