Golang | Leetcode Golang题解之第90题子集II

题目:

题解:

Go 复制代码
func subsetsWithDup(nums []int) (ans [][]int) {
    sort.Ints(nums)
    n := len(nums)
outer:
    for mask := 0; mask < 1<<n; mask++ {
        t := []int{}
        for i, v := range nums {
            if mask>>i&1 > 0 {
                if i > 0 && mask>>(i-1)&1 == 0 && v == nums[i-1] {
                    continue outer
                }
                t = append(t, v)
            }
        }
        ans = append(ans, append([]int(nil), t...))
    }
    return
}
相关推荐
creator_Li25 分钟前
Golang的Map
golang
紫陌涵光3 小时前
669. 修剪二叉搜索树
算法·leetcode
紫陌涵光5 小时前
108.将有序数组转换为二叉搜索树
数据结构·算法·leetcode
iAkuya5 小时前
(leetcode)力扣100 75前K个高频元素(堆)
java·算法·leetcode
creator_Li6 小时前
Golang的切片Slice
golang·slice
美好的事情能不能发生在我身上7 小时前
Leetcode热题100中的:哈希专题
算法·leetcode·哈希算法
逆境不可逃7 小时前
LeetCode 热题 100 之 41.缺失的第一个正数
算法·leetcode·职场和发展
We་ct9 小时前
LeetCode 173. 二叉搜索树迭代器:BSTIterator类 实现与解析
前端·算法·leetcode·typescript
踩坑记录9 小时前
leetcode hot100 79. 单词搜索 medium 递归回溯
leetcode
Rhystt11 小时前
代码随想录第二十六天|669. 修剪二叉搜索树、108.将有序数组转换为二叉搜索树、538.把二叉搜索树转换为累加树
数据结构·c++·算法·leetcode