78.Subsets

78.Subsets

题目:
https://leetcode.com/problems/subsets/

难度 : Medium

Python代码

class Solution(object):
    def subsets(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        results = [[]]
        for num in nums:
            results.extend([result + [num] for result in results])
        return results
            

可是我不能理解,为嘛我写的这个不work.

⬇️

def subsets(nums):
    """
    :type nums: List[int]
    :rtype: List[List[int]]
    """
    results = [[]]
    for num in nums:
        for result in results:
            results.extend([result + [num]])
    return results
    
    原文作者:oo上海
    原文地址: https://www.jianshu.com/p/4d9e1d92f98e
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞