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
Open every published interview problem, solution, scene, and memory room free, with no account.