class Solution {
private List[HTML_REMOVED]> paths = new ArrayList<>();
public List<List<Integer>> permutation(int[] nums) {
boolean[] st = new boolean[nums.length];
Integer[] path = new Integer[nums.length];
DFS(0, nums, st, path);
return paths;
}
public void DFS(int n, int[] nums, boolean[] st, Integer[] path){
if(n = = nums.length){
Integer[] p = new Integer[path.length];
System.arraycopy(path, 0, p, 0, path.length);
paths.add(Arrays.asList(p));
return;
}
for(int i=0; i<nums.length;i++){
if(!st[i]){
int j;
for(j=i-1;j>=0; j--){
if(nums[j]==nums[i])break;
}
if(i>=1&&j>=0&&nums[j]==nums[i]&&!st[j])continue;//相同元素规定顺序 相同的元素不能出现在后边
path[n] = nums[i];
st[i] = true;
DFS(n+1, nums, st, path);
st[i] = false;
}
}
return;
}
}