Subsets II(dfs)
Given a collection of integers that might contain duplicates,nums, return all possible subsets (the power set).
Note:The solution set must not contain duplicate subsets.
Example:
Input:
[1,2,2]
Output:
[
[2],
[1],
[1,2,2],
[2,2],
[1,2],
[]
]这里subset带重复元素问题,一定记得排序。然后 i!=pos and nums[i]==nums[i-1]: continue
python dfs:
两种方法弹入弹出path
或者
方法1
方法2:
Last updated
Was this helpful?