首页 > 其他 > 详细

78. Subsets

时间:2018-09-30 20:30:31      阅读:117      评论:0      收藏:0      [点我收藏+]

Given a set of distinct integers, nums, return all possible subsets (the power set).

Note: The solution set must not contain duplicate subsets.

Example:

Input: nums = [1,2,3]
Output:
[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]]

class Solution:
    def subsets(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        list = []
        for i in range(1,len(nums)+1):
            list.extend(itertools.combinations(nums,i))
        return list

78. Subsets

原文:https://www.cnblogs.com/bernieloveslife/p/9733242.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!