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,即爲整棵二叉樹的最大深度。
代碼AC:
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,即爲整棵二叉樹的最大深度。
代碼AC: