104. Maximum Depth of Binary Tree
问题
Given the root of a binary tree, return its maximum depth.A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
递归,每次返回左子节点和右子节点中较大的结果+1。
当节点为null时返回0。
1 | /** |
BFS搜索,每次倾倒出队列里所有的元素并将level+1。
搜索完毕返回level。
1 | class Solution { |
104. Maximum Depth of Binary Tree
https://xuanhe95.github.io/2022/04/13/104-Maximum-Depth-of-Binary-Tree/