Description
Given a string of comma-separated values representing preorder traversal with # for null, verify if it represents a valid binary tree serialization.
Examples
Input:
preorder = "9,3,4,#,#,1,#,#,2,#,6,#,#"Output:
trueExplanation:
Valid serialization.
Input:
preorder = "1, arg2 = #"Output:
falseExplanation:
For preorder = "1, arg2 = #", the answer is false because the verify preorder serialization condition is not met.
Input:
preorder = "#"Output:
Explanation:
A single null node '#' is a valid preorder serialization representing an empty tree. This is the simplest valid case where the tree has no actual nodes, just a null marker.
Constraints
- •
1 ≤ preorder.length ≤ 10⁴