数组的全排列

 public static void main(String[] args) {
        List<List<Integer>> list = m1(new int[]{1, 2, 3});
        System.out.println("");
    }


    public static List<List<Integer>> m1(int nums[]) {
        List<List<Integer>> ret = new ArrayList<>();

        if (nums.length == 1) {
            List<Integer> tmp = new ArrayList<>();
            tmp.add(nums[0]);
            ret.add(tmp);
            return ret;
        }

        for (int i = 0; i < nums.length; i++) {
            int newInt[] = new int[nums.length - 1];
            int newIndex = 0;
            for (int j = 0; j < nums.length; j++) {
                if (j != i) {
                    newInt[newIndex] = nums[j];
                    newIndex++;
                }
            }

            List<List<Integer>> ret1 = m1(newInt);
            for (List<Integer> item : ret1) {
                item.add(0, nums[i]);
                ret.add(item);
            }
        }
        return ret;
    }
原文地址:https://www.cnblogs.com/zzq-include/p/13456901.html