46. Permutations
class Solution {
List<List<Integer>> res = new ArrayList<>();
public List<List<Integer>> permute(int[] nums) {
dfs(nums, new ArrayList<>());
return res;
}
public void dfs(int[] nums, List<Integer> temp) {
if(temp.size() == nums.length) {
res.add(new ArrayList<>(temp));
return;
}
for(int i = 0; i<nums.length; i++) {
if(temp.contains(nums[i])) continue;
temp.add(nums[i]);
dfs(nums, temp);
temp.remove(temp.size() -1);
}
return;
}
}