Given a binary tree root, a node X in the tree is named good if in the path from the root to X there are no nodes with a value greater than X.val.
Return the number of good nodes in the binary tree.
3
/ \
1 4
/ / \
3 1 5
Input: root = [3, 1, 4, 3, null, 1, 5] Output: 4 Explanation: Nodes 3 (root), 3 (left-left), 4, and 5 are good. Node 1 (left child of root) is not good because 3 > 1 on the path. Node 1 (left child of 4) is not good because 4 > 1 on the path.
3
/
3
\
4
\
2
Input: root = [3, 3, null, null, 4, null, null, null, 2] Output: 3 Explanation: Nodes 3 (root), 3, and 4 are good. Node 2 is not good because 4 > 2 on the path.
[1, 10^5].-10^4 and 10^4.root = [3, 1, 4, 3, null, 1, 5]