Let’s understand binary tree creation details by a little example.
Class Definition
The Definition ofTreeNode
is the following.
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
Two Variables
root
— the variable is useful to access the binary treecurnode
— the variable is for iteration inside of the binary tree