Skip to content

Commit fefcd45

Browse files
update _47
1 parent fa51d2e commit fefcd45

File tree

1 file changed

+4
-6
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-6
lines changed

src/main/java/com/fishercoder/solutions/_47.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public List<List<Integer>> permuteUnique(int[] nums) {
1717
return result;
1818
}
1919
boolean[] used = new boolean[nums.length];
20-
Arrays.sort(nums);//this sorting is critical for the correctness of this backtracking algorithm as we compare the two adjancent neighbors to filter out possible duplicate permutations
20+
Arrays.sort(nums);//this sorting is critical for the correctness of this backtracking algorithm as we compare the two adjacent neighbors to filter out possible duplicate permutations
2121
backtracking(nums, used, new ArrayList(), result);
2222
return result;
2323
}
@@ -52,18 +52,17 @@ private void backtracking(int[] nums, boolean[] used, List<Integer> list, List<L
5252

5353
public static class Solution2 {
5454
public List<List<Integer>> permuteUnique(int[] nums) {
55-
Arrays.sort(nums);
5655
Set<List<Integer>> set = new HashSet<>();
5756
set.add(new ArrayList<>());
58-
set = recursion(nums, set, 0);
57+
set = recurse(nums, set, 0);
5958
List<List<Integer>> res = new ArrayList<>();
6059
for (List<Integer> list : set) {
6160
res.add(list);
6261
}
6362
return res;
6463
}
6564

66-
private Set<List<Integer>> recursion(int[] nums, Set<List<Integer>> set, int pos) {
65+
private Set<List<Integer>> recurse(int[] nums, Set<List<Integer>> set, int pos) {
6766
if (pos == nums.length) {
6867
return set;
6968
}
@@ -75,8 +74,7 @@ private Set<List<Integer>> recursion(int[] nums, Set<List<Integer>> set, int pos
7574
newSet.add(newList);
7675
}
7776
}
78-
set = newSet;
79-
return recursion(nums, set, pos + 1);
77+
return recurse(nums, newSet, pos + 1);
8078
}
8179
}
8280
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy