You are given the root of a binary tree, find the maximum value among all nodes in the tree. The tree can contain positive, negative, or zero values.
A Binary Tree is a tree data structure in which each node has at most two children, referred to as the left child and the right child. The tree structure is represented using TreeNode objects, where each TreeNode has a val (the node's value), a left child, and a right child. You can assume that the root node is not null.
20
The maximum value in the tree [3, 9, 20, null, null, 15, 7] is 20, which is found at the right child of the root's right child.
-5
Even with negative values, the largest value is -5, which is the root's left child.
7
A single-node tree's maximum value is its own value.
20