In a binary tree, call a node good if no node on the path from the root down to it (the node itself not included) has a bigger value than it. In other words, the node is at least as big as every ancestor. The root is always good.
Given the tree root, return the number of good nodes.
How the judge passes the data
Examples
Example 1:
Input: root = [5,3,8,2,null,7,9]
Output: 3
Explanation: The good nodes are 5 (the root), 8 and 9. The nodes 3, 2 and 7 each have a bigger ancestor (5 or 8).
Example 2:
Input: root = [4,2,6,1,3,5,7]
Output: 3
Explanation: The good nodes are 4, 6 and 7. The node 5 is not good, because its parent 6 is bigger.
Example 3:
Input: root = [2,2,2]
Output: 3
Explanation: Equal values are fine. No node has a bigger ancestor, so all 3 nodes are good.