Medium · Trees
Count Good Nodes in Binary Tree
Given the root of a non-empty binary tree, return the number of good nodes. A node is good if no node on the path from the root to it has a value greater than its own.
Examples
Example 1
[3,1,4,3,null,1,5]Output: 4 good nodes
Example 2
[3,3,null,4,2]Output: 3 good nodes
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.