Skip to content

Commit 8d838e4

Browse files
committed
Update serialize-and-deserialize-binary-tree.py
1 parent 0b8f9a6 commit 8d838e4

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Python/serialize-and-deserialize-binary-tree.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Time: O(n)
2-
# Space: O(n)
2+
# Space: O(h)
33

44
# Serialization is the process of converting a data structure or
55
# object into a sequence of bits so that it can be stored in a file
@@ -67,5 +67,19 @@ def deserializeHelper():
6767
node.left = deserializeHelper()
6868
node.right = deserializeHelper()
6969
return node
70-
vals = iter(data.split())
70+
def isplit(source, sep):
71+
sepsize = len(sep)
72+
start = 0
73+
while True:
74+
idx = source.find(sep, start)
75+
if idx == -1:
76+
yield source[start:]
77+
return
78+
yield source[start:idx]
79+
start = idx + sepsize
80+
vals = iter(isplit(data, ' '))
7181
return deserializeHelper()
82+
83+
# Your Codec object will be instantiated and called as such:
84+
# codec = Codec()
85+
# codec.deserialize(codec.serialize(root))

0 commit comments

Comments
 (0)