Explanation:Nodes in blue are good.
Root Node (3) is always a good node.
Node 4 -> (3,4) is the maximum value in the path starting from the root.
Node 5 -> (3,4,5) is the maximum value in the path
Node 3 -> (3,1,3) is the maximum value in the path.
Example 2:
Input:root = [3,3,null,4,2]
Output:3
Explanation:Nodes 3 (root), 3 (path 3->3), 4 (path 3->3->4) are good. Node 2 (path 3->3->2) is not good, because 3 (on its path) is higher than 2.
Example 3:
Input:root = [1]
Output:1
Explanation:The root node (1) is always considered good, as there are no preceding nodes to compare against.