<jupyter_start><jupyter_text>说明：    1、编写程序以查找第n个丑数。丑数是正数，其主要因子仅包括2、3、5。Example:    Input: n = 10    Output: 12    Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers.Note:      1、1 is typically treated as an ugly number.    2、n does not exceed 1690.<jupyter_code># 时间复杂度 NlogN
class Solution:
    def nthUglyNumber(self, n: int) -> int:
        res = [1]
        for i in range(n):
            num = res.pop(0)
            val_2 = num * 2
            val_3 = num * 3
            val_5 = num * 5
            if val_2 not in res:
                res.append(val_2)
            if val_3 not in res:
                res.append(val_3)
            if val_5 not in res:
                res.append(val_5)
            res.sort()
        return num
class Solution:
    def nthUglyNumber(self, n: int) -> int:
        nums = [1]
        p2 = p3 = p5 = 0
        for i in range(n-1):
            temp = min(nums[p2] * 2, nums[p3] * 3, nums[p5] * 5)
            nums.append(temp)
            if temp == nums[p2] * 2:
                p2 += 1
            if temp == nums[p3] * 3:
                p3 += 1
            if temp == nums[p5] * 5:
                p5 += 1
            print(nums, p2, p3, p5)
        return nums[-1]
n_ = 10
solution = Solution()
solution.nthUglyNumber(n_)
a = [0, 2, 4, 1]
print(a.remove(0))
a
a = set([3,4,5,6,9, 1, 2,0, 11, 22, -1, 255, 6])
a<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1266713581984518, 'fraction_numerical': 0.06685432793807178, 'mean_word_length': 1.5667870036101084, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '143664', 'license': 'Apache-2.0', 'n_tokens_mistral': 617, 'n_tokens_neox': 564, 'n_words': 158, 'path': 'Math/0826/264. Ugly Number II.ipynb', 'repo_name': 'YuHe0108/Leetcode', 'size': '1421'}