78_Subsets
[Medium][Backtracking]
Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
Solution:
Idea:
For each integer, use recursion to get subsets for the two possibilities:
the subset includes the integer
the subset doesn't include the integer
For storing each solution, there are two ways:
initialize a list called sol, update the elements when we progress.
In the helper function, set a parameter called selected__so__far, which includes all the selected integers. Update this parameter when we progress.
Code 1: use a list to update current solution
Code 2: use a parameter in the helper function to store current solution
Solution 2: Mit Manipulation
Last updated