Subsets II

原创 2015年07月07日 11:29:45
public class Solution {
    public List<List<Integer>> subsetsWithDup(int[] nums) {
        List<List<Integer>> result = new ArrayList<List<Integer>>();
        if (nums == null || nums.length < 1) {
            return result;
        }
        List<Integer> level = new ArrayList<Integer>();
        Arrays.sort(nums);
        dfs(result, level, 0, nums);
        return result;
    }
    private void dfs(List<List<Integer>> result, List<Integer> level, int loc, int[] nums) {
        result.add(new ArrayList<Integer>(level));
        for (int i = loc; i < nums.length; i++) {
            if (i != loc&& nums[i] == nums[i - 1]) {
                continue;
            }
            level.add(nums[i]);
            dfs(result, level, i + 1, nums);
            level.remove(level.size() - 1);
        }
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Leetcode : Subsets II

URL:https://leetcode.com/problems/subsets-ii/#/description题目大意:Given a collection of integers that m...

leetcode 90. Subsets II

Given a collection of integers that might contain duplicates, nums, return all possible subsets. ...

【leetcode】90. Subsets II

leetcode, subsets ||, 3种解法

leetcode:暴力枚举法之Subsets II

leetcode:暴力枚举法之Subsets II 题目; Given a collection of integers that might contain duplicates, S, retur...

LeetCode OJ:Subsets II

Subsets II   Given a collection of integers that might contain duplicates, S, return all possible...

[leetcode 78 & 90, Medium] Subsets I and II

Subsets I and II

Subsets II -- leetcode

Given a collection of integers that might contain duplicates, S, return all possible subsets. Not...

leetcode 90 Subsets II

leetcode 90 Subsets II c++ Python

[LeetCode][Java] Subsets II

题目: Given a collection of integers that might contain duplicates, nums, return all possible sub...

leetcode -day31 Subsets I II

1、  Subsets Given a set of distinct integers, S, return all possible subsets. Note: Elements in...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)