import java.util.*;
public class Solution { public ArrayList<ArrayList> permute(int[] num) { ArrayList<ArrayList> result = new ArrayList<>(); ArrayList list = new ArrayList<>(); backTrack(num,list,result); return result; } private void backTrack(int[] num, ArrayList list, ArrayList<ArrayList> result){ if(list.size() == num.length){ result.add(new ArrayList(list)); return; } for(int i = 0;i<num.length;i++){ if(list.contains(num[i])){ continue; } list.add(num[i]); backTrack(num,list,result); list.remove(list.size()-1); } } }