The original title link is here: https://leetcode.com/problems/permutations-ii/
It is the advanced topic of permutations. Iteration method and Subsets II are like, add newres before check whether the Newres contains duplicate item, no repetition can add in.
AC Java:
1 Public classSolution {2 PublicList<list<integer>> Permuteunique (int[] nums) {3list<list<integer>> res =NewArraylist<list<integer>>();4 if(Nums = =NULL|| Nums.length = = 0){5 returnRes;6 }7list<integer> item =NewArraylist<integer>();8Item.add (nums[0]);9 Res.add (item);Ten for(inti = 1; i<nums.length; i++){ OneList<list<integer>> newres =NewArraylist<list<integer>>(); A for(intj = 0; J<res.size (); J + +){ -List<integer> cur =Res.get (j); - for(intK=0;k<cur.size () +1;k++){ theitem =NewArraylist<integer>(cur); - Item.add (K,nums[i]); - if(!newres.contains (item)) { - Newres.add (item); + } - } + } Ares =Newres; at } - returnRes; - } -}
Leetcode permutations II