In each iteration, put the new number to all possible place.

To avoid duplicate we also have to:

- For duplicate numbers in a row, only add same number in in front of them.
- Break when same number exists in the permutation.

```
public class Solution {
public List<List<Integer>> permuteUnique(int[] nums) {
LinkedList<List<Integer>> r = new LinkedList<>();
r.add(new ArrayList<Integer>());
for(int i=0; i<nums.length; i++){
int n = r.size();
for(int j=0; j<n; j++){
List<Integer> list = r.poll();
for(int k=0; k<=list.size(); k++){
if(k > 0 && list.get(k-1) == nums[i])
break;
ArrayList<Integer> t = new ArrayList<>(list);
t.add(k, nums[i]);
r.offer(t);
}
}
}
return r;
}
}
```