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