<awangdev>46. Permutations_6.java
public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> rst = new ArrayList<>();
        if (nums == null || nums.length == 0) return rst;
        
        List<Integer> numList = new ArrayList<>();
        for (int num : nums) numList.add(num);
        
        int n = nums.length;
        Queue<List<Integer>> queue = new LinkedList<>();
        queue.offer(new ArrayList<>());

        while (!queue.isEmpty()) {
            List<Integer> list = queue.poll();
            if (list.size() == n) {
                rst.add(new ArrayList<>(list));
                continue;
            }
            List<Integer> candidates = new ArrayList<>(numList);
            candidates.removeAll(list);
            for (int num : candidates) {
                list.add(num);
                queue.offer(new ArrayList<>(list));
                list.remove(list.size() - 1);
            }
        }

        return rst;
    }
public List < List < Integer >> var_2 ( int [ ] var_3 ) {
  List < List < Integer >> var_5 = new ArrayList < > ( ) ;
  if ( var_3 == null || var_3 . length == 0 ) return var_5 ;
  List < Integer > var_9 = new ArrayList < > ( ) ;
  for ( int var_10 : var_3 ) var_9 . add ( var_10 ) ;
  int var_12 = var_3 . length ;
  Queue < List < Integer >> var_15 = new LinkedList < > ( ) ;
  var_15 . offer ( new ArrayList < > ( ) ) ;
  while ( ! var_15 . isEmpty ( ) ) {
    List < Integer > var_19 = var_15 . poll ( ) ;
    if ( var_19 . size ( ) == var_12 ) {
      var_5 . add ( new ArrayList < > ( var_19 ) ) ;
      continue ;
    }
    List < Integer > var_21 = new ArrayList < > ( var_9 ) ;
    var_21 . removeAll ( var_19 ) ;
    for ( int var_10 : var_21 ) {
      var_19 . add ( var_10 ) ;
      var_15 . offer ( new ArrayList < > ( var_19 ) ) ;
      var_19 . remove ( var_19 . size ( ) - 1 ) ;
    }
  }
  return var_5 ;
}
