We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent df4a3de commit 656909fCopy full SHA for 656909f
Python/serialize-and-deserialize-binary-tree.py
@@ -1,5 +1,5 @@
1
# Time: O(n)
2
-# Space: O(n)
+# Space: O(h)
3
4
# Serialization is the process of converting a data structure or
5
# object into a sequence of bits so that it can be stored in a file
@@ -67,5 +67,19 @@ def deserializeHelper():
67
node.left = deserializeHelper()
68
node.right = deserializeHelper()
69
return node
70
- vals = iter(data.split())
+ 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, ' '))
81
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