0
我的代碼將崩潰,永遠運行下去:Python的功能集,想不通我的錯誤
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
雖然我用Google搜索,並找到類似的解決方案:
def subsets(nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
results = [[]]
for num in nums:
results.extend([result + [num] for result in results])
return results
這裏有什麼區別?