public List<List<Integer>> permute(int[] nums) {
List<List<Integer>> res = new ArrayList<List<Integer>>();
if(nums==null)
return res;
backtrack(res, new ArrayList<>(),nums);
return res;
}
public void backtrack(List<List<Integer>> res, ArrayList<Integer> tempList, int[] nums){
if(tempList.size()==nums.length){
res.add(new ArrayList(tempList));
}
for(int i=0;i<nums.length;i++){
if(tempList.contains(nums[i])) continue;
else{
tempList.add(nums[i]);
backtrack(res,tempList,nums);
tempList.remove(tempList.size()-1);
}
}
}