码迷,mamicode.com
首页 > 其他好文 > 详细

Subsets II

时间:2015-04-16 13:53:09      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

public class Solution {
    public ArrayList<ArrayList<Integer>> subsetsWithDup(int[] num) {
        ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>();
        res.add(new ArrayList<Integer>());
        if(num==null || num.length==0) return res;
        Arrays.sort(num);
        int start=0; 
        for(int i=0; i<num.length;i++){
            int len = res.size();
            for(int j= start; j<len; j++){
                ArrayList<Integer> tmp = new ArrayList<Integer>(res.get(j));
                tmp.add(num[i]);
                res.add(tmp);
            }
            if(i<num.length-1 && num[i]==num[i+1]){
                start = len; // let those processed data go for the dup one
            }else
                start =0;
        }
        return res;
    }
}

ref http://blog.csdn.net/linhuanmars/article/details/24613193

Subsets II

标签:

原文地址:http://www.cnblogs.com/jiajiaxingxing/p/4431726.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!