# 4.2 All permutations with duplicate elements

Solution: Use a set to record all distinct elements.

```java
Set<Character> used = new HashSet<>();
for (int i = index; i < array.length; i++) {
  if (used.add(array[i])) {	//returns true if not exist in the set
    //swap-swap
  }
}
```
