1448. Count Good Nodes in Binary Tree
1 | class Solution { |
没什么好说的就是记录一个max即可. 这个就是回溯模板做. 我们不需要下面的node来提供信息给我们来确定当前的答案, 而是边走边统计. 也就是traverse.
时间复杂度: O(n)
空间复杂度: O(n)
Insist on doing small things, then witness the magic
1 | class Solution { |
没什么好说的就是记录一个max即可. 这个就是回溯模板做. 我们不需要下面的node来提供信息给我们来确定当前的答案, 而是边走边统计. 也就是traverse.
时间复杂度: O(n)
空间复杂度: O(n)