题解 | #子集-ii#

子集-ii

http://www.nowcoder.com/practice/66cf0498e9fd4730ab453dac978bf7e6

来个莫名AC的(bushi)

import java.util.*;
public class Solution {
    ArrayList<ArrayList<Integer>> res = new ArrayList<>();
    ArrayList<Integer> path = new ArrayList<>();
    public ArrayList<ArrayList<Integer>> subsetsWithDup(int[] num) {
        Arrays.sort(num);
        dfs(num,0);
        return res;
    }

    public void dfs(int[] num , int index){
        if(!res.contains(path)){
            res.add(new ArrayList<>(path));
        }

        for(int i = index ; i < num.length ; i++){
            path.add(num[i]);
            dfs(num,i+1);
            path.remove(path.size()-1);
        }
    }
}
全部评论

相关推荐

鬼迹人途:你去投一投尚游游戏,服务器一面,第一个图算法,做完了给你一个策略题,你给出方案他就提出低概率问题,答不上当场给你挂
点赞 评论 收藏
分享
醉蟀:你不干有的是人干
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务