题解 | 集合的所有子集(一)

集合的所有子集(一)

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

全部评论

相关推荐

06-26 17:24
已编辑
宁波大学 golang
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务