1448. Count Good Nodes in Binary Tree
Question
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.
Solution
DFS搜索,每次传入当前分支的最大值。
如果当前值大于等于最大值,则count+1。
Code
1 | /** |
1448. Count Good Nodes in Binary Tree
https://xuanhe95.github.io/2022/09/01/1448-Count-Good-Nodes-in-Binary-Tree/