Given a collection of numbers that might contain duplicates, return all possible unique permutations.
[1,1,2] have the following unique permutations:
[1,1,2], [1,2,1], and [2,1,1].
Solution. Solution is inspired from here. This is a very good one. First we sort the array. We should set a a used array. When we use num[i], if num[i] == num[i – 1], we should check if we move on. If num[i] == num[i – 1], and num[i – 1] is not used, then we shouldn’t move on.
This is a very good case for permutation. I have other permutation case from here.
check my code on github: link