File tree Expand file tree Collapse file tree 1 file changed +76
-1
lines changed Expand file tree Collapse file tree 1 file changed +76
-1
lines changed Original file line number Diff line number Diff line change @@ -250,9 +250,84 @@ used数组可是全局变量,每层与每层之间公用一个used数组,所
250
250
251
251
Java:
252
252
253
-
254
253
Python:
255
254
255
+ **90.子集II**
256
+
257
+ ```python
258
+ class Solution:
259
+ def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
260
+ res = []
261
+ nums.sort()
262
+ def backtracking(start, path):
263
+ res.append(path)
264
+ uset = set()
265
+ for i in range(start, len(nums)):
266
+ if nums[i] not in uset:
267
+ backtracking(i + 1, path + [nums[i]])
268
+ uset.add(nums[i])
269
+
270
+ backtracking(0, [])
271
+ return res
272
+ ```
273
+
274
+ ** 40. 组合总和 II**
275
+
276
+ ``` python
277
+ class Solution :
278
+ def combinationSum2 (self , candidates : List[int ], target : int ) -> List[List[int ]]:
279
+
280
+ res = []
281
+ candidates.sort()
282
+
283
+ def backtracking (start , path ):
284
+ if sum (path) == target:
285
+ res.append(path)
286
+ elif sum (path) < target:
287
+ used = set ()
288
+ for i in range (start, len (candidates)):
289
+ if candidates[i] in used:
290
+ continue
291
+ else :
292
+ used.add(candidates[i])
293
+ backtracking(i + 1 , path + [candidates[i]])
294
+
295
+ backtracking(0 , [])
296
+
297
+ return res
298
+ ```
299
+
300
+ ** 47. 全排列 II**
301
+
302
+ ``` python
303
+ class Solution :
304
+ def permuteUnique (self , nums : List[int ]) -> List[List[int ]]:
305
+ path = []
306
+ res = []
307
+ used = [False ]* len (nums)
308
+
309
+ def backtracking ():
310
+ if len (path) == len (nums):
311
+ res.append(path.copy())
312
+
313
+ deduplicate = set ()
314
+ for i, num in enumerate (nums):
315
+ if used[i] == True :
316
+ continue
317
+ if num in deduplicate:
318
+ continue
319
+ used[i] = True
320
+ path.append(nums[i])
321
+ backtracking()
322
+ used[i] = False
323
+ path.pop()
324
+ deduplicate.add(num)
325
+
326
+ backtracking()
327
+
328
+ return res
329
+ ```
330
+
256
331
257
332
Go:
258
333
You can’t perform that action at this time.
0 commit comments