Count Good Nodes in Binary Tree
You are given the root of a binary tree. On the path from the root down to a node, the node is good if no value on that path (before it) is larger than the node's own value. The root is always good. Return the number of good nodes. An empty tree gives 0.
Trees appear in the tests in level order, with null for a missing child, like [3,9,20,null,null,15,7]. Each node is a TreeNode with .val, .left and .right; the class is already defined for you.
Example 1
root [3,1,4,3,null,1,5]
returns 4
Good nodes: 3 (root), 4, 3 (under 1), 5. The two 1s are not.
Constraints
0 <= number of nodes <= 100-100 <= node.val <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.