334. Count Good Nodes in Binary Tree
MediumTree
Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Return the number of good nodes in the binary tree.
Examples
Input: [3,1,4,3,null,1,5]
Output: 4
Explanation: Nodes 3 (root), 3, 4, and 5 each have no larger value on their root path.
Constraints
- The number of nodes in the binary tree is in the range [1, 10^5].
- Each node's value is between [-10^4, 10^4].
Loading...
Run checks all cases above. Submit evaluates all test cases.