Golang | Leetcode Golang题解之第313题超级丑数

题目:

题解:

Go 复制代码
func nthSuperUglyNumber(n int, primes []int) int {
    dp := make([]int, n+1)
    m := len(primes)
    pointers := make([]int, m)
    nums := make([]int, m)
    for i := range nums {
        nums[i] = 1
    }
    for i := 1; i <= n; i++ {
        minNum := math.MaxInt64
        for j := range pointers {
            minNum = min(minNum, nums[j])
        }
        dp[i] = minNum
        for j := range nums {
            if nums[j] == minNum {
                pointers[j]++
                nums[j] = dp[pointers[j]] * primes[j]
            }
        }
    }
    return dp[n]
}

func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}
相关推荐
6Hzlia1 小时前
【Hot 100 刷题计划】 LeetCode 48. 旋转图像 | C++ 矩阵变换题解
c++·leetcode·矩阵
Morwit3 小时前
【力扣hot100】 1. 两数之和
数据结构·c++·算法·leetcode·职场和发展
py有趣3 小时前
力扣热门100题之岛屿的数量(DFS/BFS经典题)
leetcode·深度优先·宽度优先
qinian_ztc4 小时前
frida 14.2.18 安装报错解决
算法·leetcode·职场和发展
Wenweno0o5 小时前
Eino - 错误处理与稳定性
golang·智能体·eino
田梓燊6 小时前
2026/4/11 leetcode 3741
数据结构·算法·leetcode
王码码20356 小时前
Go语言中的Elasticsearch操作:olivere实战
后端·golang·go·接口
Tomhex6 小时前
Go语言import用法详解
golang·go
小肝一下8 小时前
每日两道力扣,day8
c++·算法·leetcode·哈希算法·hot100
Tomhex8 小时前
Golang空白导入的真正用途
golang·go