# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = NoneclassCodec:defserialize(self, root: TreeNode)->str:"""Encodes a tree to a single string.
"""defpreorder(root):ifnot root:return[]return[root.val]+ preorder(root.left)+ preorder(root.right)return','.join(map(str, preorder(root)))defdeserialize(self, data:str)-> TreeNode:"""Decodes your encoded data to tree.
"""ifnot data:returnNone
pres =list(map(int, data.split(',')))return self.buildtree(pres,0,len(pres)-1)defbuildtree(self, nums, l, r):if l > r:returnNone
mid = l +1while mid <= r and nums[l]> nums[mid]: mid +=1
root = TreeNode(nums[l])
root.left = self.buildtree(nums, l +1, mid -1)
root.right = self.buildtree(nums, mid, r)return root
# Your Codec object will be instantiated and called as such:# Your Codec object will be instantiated and called as such:# ser = Codec()# deser = Codec()# tree = ser.serialize(root)# ans = deser.deserialize(tree)# return ans
classSolution:defsubsets(self, nums: List[int])-> List[List[int]]:
n =len(nums)
I =1<< n
mark =dict()
j =1
ans =[]for i inrange(10):
mark[j]= i
j <<=1for i inrange(I):
data = i
arr =[]while data:
idx = data &-data
arr.append(nums[mark[idx]])
data &= data -1
ans.append(arr)return ans