1.题目描述
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
给定一个可包含重复数字的序列,返回所有不重复的全排列。
Example:
Input: [1,1,2]
Output:
[
[1,1,2],
[1,2,1],
[2,1,1]
]
2.Solutions
Use an extra boolean array “ boolean[] used” to indicate whether the value is added to list.
Sort the array “int[] nums” to make sure we can skip the same value.
when a number has the same value with its previous, we can use this number only if his previous is used
1 | public static List<List<Integer>> permuteUnique(int[] nums) { |