import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param num int整型一维数组 * @return int整型ArrayList<ArrayList<>> */ ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>(); ArrayList<Integer> nums = new ArrayList<Integer>(); public ArrayList<ArrayList<Integer>> permute (int[] num) { // write code here boolean[] vis = new boolean[num.length]; Arrays.sort(num); recursion(num, vis); return res; } public void recursion(int[] num, boolean[] vis) { if (nums.size() == num.length) { res.add(new ArrayList<>(nums)); } else { for (int i = 0; i < num.length; i++) { if (vis[i])continue; nums.add(num[i]); vis[i] = true; recursion(num, vis); nums.remove(nums.size()-1); vis[i] = false; } } } }