Tree Traverse
Last updated
Last updated
Symmetric Tree - determine whether a binary tree is symmetric:
It's pretty similar to the same tree problem:
Both use preorder traverse mechanism, pass the result (check result) back through the tree traverse.
Maximum Depth of Binary Tree - find the maximum depth of a binary tree:
Traverse the tree with preorder, pass the result(depth) back through the traverse.
Validate Binary Search Tree - determine whether a binary tree is a valid binary search tree (BST):
An advanced preorder traverse, where need to pass more inform through the traverse. pretty smart way to pass the min and max through
Still use preorder traverse, however need to address two edge cases, one is when root is null, need to return false, another case is the definition of leaf node, only when left and right node both are null, we can say it's a leaf node.
Path Sum - determine if a binary tree has a root-to-leaf path such that adding up all the values along the path equals a given target sum: