标签:serial 中序 重构 题目 col otv order 修改 lis
1 class Solution: 2 def Serialize(self, root): 3 # write code here 4 retList = [] 5 def preOrder(root): 6 if root == None: 7 retList.append("#") 8 return 9 retList.append(str(root.val)) 10 preOrder(root.left) 11 preOrder(root.right) 12 preOrder(root) 13 return ‘ ‘.join(retList) 14 def Deserialize(self, s): 15 # write code here 16 retList = s.split() 17 def dePreOrder(): 18 if retList == []: 19 return None 20 rootVal = retList[0] 21 del retList[0] 22 if rootVal == "#": 23 return None 24 node = TreeNode(int(rootVal)) 25 leftNode = dePreOrder() 26 rightNode = dePreOrder() 27 node.left = leftNode 28 node.right = rightNode 29 return node 30 pRoot = dePreOrder() 31 return pRoot
2020-01-01 19:34:24
标签:serial 中序 重构 题目 col otv order 修改 lis
原文地址:https://www.cnblogs.com/NPC-assange/p/12129602.html