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


代碼AC:


發佈了36 篇原創文章 · 獲贊 1 · 訪問量 9537
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章