104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
题意:
给定一个二叉树,求其最大深度。
最大深度是从根节点到最远叶节点的最长路径上的节点数。
思路:
方法一:
递归实现,利用二叉树的递归求二叉树树高:
1 | class Solution { |
方法二:
利用二叉树的非递归层序遍历求树高:
1 | class Solution { |