<awangdev>Subsets II_4.java
public ArrayList<ArrayList<Integer>> subsetsWithDup(ArrayList<Integer> S) {
    	ArrayList<ArrayList<Integer>> rst = new ArrayList<ArrayList<Integer>>();
    	if (S == null || S.size() == 0) {
    		return rst;
    	}
    	Collections.sort(S);
    	Queue<ArrayList<Integer>> queue = new LinkedList<ArrayList<Integer>>();
    	ArrayList<Integer> list = new ArrayList<Integer>();
    	queue.offer(new ArrayList<Integer>(list));
    	rst.add(new ArrayList<Integer>(list));
    	
    	for (int i = 0; i < S.size(); i++) {
    		int num = S.get(i);
    		int size = queue.size();
    		while(size > 0) {
	    		list = queue.poll();
	    		list.add(num);
	    		if (!rst.contains(list)) {
	    			rst.add(new ArrayList<Integer>(list));
	    		}
	    		queue.offer(new ArrayList<Integer>(list));
	    		list.remove(list.size() - 1);
	    		queue.offer(new ArrayList<Integer>(list));
	    		size--;
	    	}
    	}
    	return rst;
    }
public ArrayList < ArrayList < Integer >> var_2 ( ArrayList < Integer > var_3 ) {
  ArrayList < ArrayList < Integer >> var_4 = new ArrayList < ArrayList < Integer >> ( ) ;
  if ( var_3 == null || var_3 . size ( ) == 0 ) {
    return var_4 ;
  }
  Collections . sort ( var_3 ) ;
  Queue < ArrayList < Integer >> var_12 = new LinkedList < ArrayList < Integer >> ( ) ;
  ArrayList < Integer > var_13 = new ArrayList < Integer > ( ) ;
  var_12 . offer ( new ArrayList < Integer > ( var_13 ) ) ;
  var_4 . add ( new ArrayList < Integer > ( var_13 ) ) ;
  for ( int var_16 = 0 ;
  var_16 < var_3 . size ( ) ;
  var_16 ++ ) {
    int var_18 = var_3 . get ( var_16 ) ;
    int size = var_12 . size ( ) ;
    while ( size > 0 ) {
      var_13 = var_12 . poll ( ) ;
      var_13 . add ( var_18 ) ;
      if ( ! var_4 . contains ( var_13 ) ) {
        var_4 . add ( new ArrayList < Integer > ( var_13 ) ) ;
      }
      var_12 . offer ( new ArrayList < Integer > ( var_13 ) ) ;
      var_13 . remove ( var_13 . size ( ) - 1 ) ;
      var_12 . offer ( new ArrayList < Integer > ( var_13 ) ) ;
      size -- ;
    }
  }
  return var_4 ;
}
