Back to course home
0% completed
Vote For New Content
Solution: Count Good Nodes in Binary Tree
Problem Statement
Given a binary tree root
, return the number of good
nodes in the binary tree.
A node is considered good
if in the path from the root to this node, there are no nodes with a value greater than
this node's value.
Examples
Example 1
- Input: root =
[3, 1, 3, 3, null, 1, 5]
- Expected Output:
4
- Explanation:
- Root node (3) is always good.
- Node
5
is also a good node. - Both nodes
3
are good.
Example 2
- Input: root =
[2, 3, 4, 1, null, null, 5]
- Expected Output:
4
- Explanation:
- Nodes
2
,3
, `4
- Nodes
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page