LC090 - Subsets II
Problem
Given an integer array nums
that may contain duplicates, return all possible
subsets
(the power set).
The solution set must not contain duplicate subsets. Return the solution in any order.
Example
Input: nums = [1,2,2]
Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
Solution
Backtracking
Do a DFS and backtrack to get all subsets. Time and space complexity is .
Bit Masking
Use bit masking to come up with the power set. Replace pow with bit shift to speed up computation.
Time complexity is still but with a smaller constant time factor than the backtracking solution.
Last updated