One way to serialize a binary tree is to use preorder traversal. In this traversal, a non-null node’s value is recorded, while a null node is represented by a sentinel value such as '#'.
Given a string preorder of comma-separated values, determine whether it represents a valid preorder traversal serialization of a binary tree. Return true if it is valid, or false otherwise.
Note: It is guaranteed that each comma-separated value in the string will be either an integer or the character
'#'representing a null pointer. You must not reconstruct the actual binary tree.
Constraints:
preorder.length
preorder consists of integers in the range '#' separated by commas ','.
One way to serialize a binary tree is to use preorder traversal. In this traversal, a non-null node’s value is recorded, while a null node is represented by a sentinel value such as '#'.
Given a string preorder of comma-separated values, determine whether it represents a valid preorder traversal serialization of a binary tree. Return true if it is valid, or false otherwise.
Note: It is guaranteed that each comma-separated value in the string will be either an integer or the character
'#'representing a null pointer. You must not reconstruct the actual binary tree.
Constraints:
preorder.length
preorder consists of integers in the range '#' separated by commas ','.