public class Solution {
public ArrayList<ArrayList<Integer>> permute(int[] num) {
ArrayList<ArrayList<Integer>> result = new ArrayList<>();
LinkedList<Integer> list = new LinkedList<>();
backTrack(num,list,result);
return result;
}
private void backTrack(int[] num, LinkedList<Integer> list, ArrayList<ArrayList<Integer>> result){
if(list.size() == num.length){
result.add(new ArrayList<Integer>(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.removeLast();
}
}
}