MCPcopy
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / Serialize

Method Serialize

Target Offer/序列化二叉树.py:12–26  ·  view source on GitHub ↗
(self, root)

Source from the content-addressed store, hash-verified

10 self.right = None
11class Solution:
12 def Serialize(self, root):
13 serializeStr = ''
14 if root == None:
15 return '#'
16 stack = []
17 while root or stack:
18 while root:
19 serializeStr += str(root.val) + ','
20 stack.append(root)
21 root = root.left
22 serializeStr += '#,'
23 root = stack.pop()
24 root = root.right
25 serializeStr = serializeStr[:-1]
26 return serializeStr
27
28 def Deserialize(self, s):
29 serialize = s.split(',')

Callers

nothing calls this directly

Calls 1

popMethod · 0.45

Tested by

no test coverage detected