class Solution(object): def subsets(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ if nums==None: return  elif nums==: return [] res= self.helper(nums,,res,0) return res def helper(self,nums,tmp,res,i): if i==len(nums): res.append(tmp[:]) return self.helper(nums,tmp,res,i+1) tmp.append(nums[i]) self.helper(nums,tmp,res,i+1) tmp.remove(tmp[-1])
@mada0304 why do you append tmp[:] instead of tmp? I thought they were the same but append tmp does not work.
if you use "tmp", every "tmp" from here will change. if you have time, you can look some about copy module and learn different copy type. You will understand why~
@MaoDD tmp will be a pointer, and tmp[:] will be a copy.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.