原题见leetcode的subSets和subsetsWithDup,本篇文章着重采用“增量构造法”,解决此类问题。当然,还有其他办法,如递归法、位向量法等。
首先看subSets题目:https://oj.leetcode.com/problems/subsets/,描述如下:
Given a set of distinct integers, S, return all possible subsets.
Note:
- Elements in a subset must be in non-descending order.
- The solution set must not contain duplicate subsets.