Skip to content

Commit 2e10621

Browse files
committed
added type hints
1 parent 5923c92 commit 2e10621

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: data_structures/binary_tree/serialize_deserialize_binary_tree.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
class TreeNode:
24
"""
35
A binary tree node has a value, left child, and right child.
@@ -8,7 +10,7 @@ class TreeNode:
810
right: The right child of the node.
911
"""
1012

11-
def __init__(self, val: int = 0, left=None, right=None) -> None:
13+
def __init__(self, val: int = 0, left:TreeNode = None, right:TreeNode = None) -> None:
1214
if not isinstance(val, int):
1315
raise TypeError("Value must be an integer.")
1416
self.val = val
@@ -118,7 +120,7 @@ def deserialize(data: str) -> TreeNode:
118120
# Split the serialized string by comma to get node values
119121
nodes = data.split(",")
120122

121-
def build_tree():
123+
def build_tree() -> TreeNode:
122124
# Get the next value from the list
123125
val = nodes.pop(0)
124126

0 commit comments

Comments
 (0)