1. 程式人生 > >leetcode-47-Permutations II

leetcode-47-Permutations II

Similar thing with previous one, but we need to take care of the duplicate. How to do this? First, sort the array, then if current element is the same as its previous one and previous one not used yet, do not select current one. In other word, use the first element firstly.

Error:
1. Do not check if the array is empty or not
2. Do not know how to check duplicate. We need to use “if(i > 0 && nums[i] == nums[i - 1] && !used[i - 1])” to check it