File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -166,7 +166,7 @@ if (i > startIndex && nums[i] == nums[i - 1] ) {
166
166
167
167
168
168
### Java
169
-
169
+ 使用used数组
170
170
``` java
171
171
class Solution {
172
172
List<List<Integer > > result = new ArrayList<> ();// 存放符合条件结果的集合
@@ -202,6 +202,37 @@ class Solution {
202
202
}
203
203
```
204
204
205
+ 不使用used数组
206
+ ``` java
207
+ class Solution {
208
+
209
+ List<List<Integer > > res = new ArrayList<> ();
210
+ LinkedList<Integer > path = new LinkedList<> ();
211
+
212
+ public List<List<Integer > > subsetsWithDup ( int [] nums ) {
213
+ Arrays . sort( nums );
214
+ subsetsWithDupHelper( nums, 0 );
215
+ return res;
216
+ }
217
+
218
+
219
+ private void subsetsWithDupHelper ( int [] nums , int start ) {
220
+ res. add( new ArrayList<> ( path ) );
221
+
222
+ for ( int i = start; i < nums. length; i++ ) {
223
+ // 跳过当前树层使用过的、相同的元素
224
+ if ( i > start && nums[i - 1 ] == nums[i] ) {
225
+ continue ;
226
+ }
227
+ path. add( nums[i] );
228
+ subsetsWithDupHelper( nums, i + 1 );
229
+ path. removeLast();
230
+ }
231
+ }
232
+
233
+ }
234
+ ```
235
+
205
236
### Python
206
237
``` python
207
238
class Solution :
You can’t perform that action at this time.
0 commit comments