题目二:
寻找所有可能子集合
输入[1,2,3],输出[[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]
def FindSubset(lists):
if len(lists) == 0:
return [[]]
subsets = []
first_elt = lists[0]
rest_list = lists[1:]
for partial_sebset in FindSubset(rest_list):
subsets.append(partial_sebset)
next_subset = partial_sebset[:] + [first_elt]
subsets.append(next_subset)
return subsets
网友评论