python solution using method about binary


  • 0
    C
    class Solution(object):
        def subsets(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            n=len(nums)
            ans=[]
            for i in range(0,2**n):
                tmp=[]
                k=i
                for j in range(0,n):
                    if k%2==1:
                        tmp.append(nums[j])
                    k=k/2
                #print tmp
                ans.append(tmp)
            return ans
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.