Thoughts Basic idea: For each number in the array, swap it with every element after it. To avoid duplicate, need to check it first. Java Solution public ArrayList
> permuteUnique(int[] num) { ArrayList> result = new ArrayList>(); permuteUnique(num, 0, result); return result; } private void permuteUnique(int[] num, int start, ArrayList> result) { if (start >= num.length ) { ArrayList item = convertArrayToList(num); result.add(item); } for (int j = start; j <= num.length-1; j++) { if (containsDuplicate(num,
Read full article from LeetCode – Permutations II (Java)
No comments:
Post a Comment