leetcode-47-Permutations II

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zem_nezer/article/details/85087875

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

猜你喜欢

转载自blog.csdn.net/zem_nezer/article/details/85087875