题解 | 集合的所有子集(一)
集合的所有子集(一)
https://www.nowcoder.com/practice/c333d551eb6243e0b4d92e37a06fbfc9
class Solution: def subsets(self , S: List[int]) -> List[List[int]]: # write code here res = [] def dfs(i:int,path): res.append(path[:]) for j in range(i,len(S)): path.append(S[j]) dfs(j+1,path) path.pop() dfs(0,[]) res.sort(key=lambda x:(len(x),x)) return res