题目:
题目链接: https://leetcode-cn.com/problems/subsets/
解题思路:
"所有可能",回溯 + 剪枝
代码实现:
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
def create_res(start, nums, res, path):
for index in range(start, len(nums)):
path.append(nums[index])
res.append(path[:])
create_res(index + 1, nums, res, path)
path.pop()
res = [[]]
create_res(0, nums, res, [])
return res