Leetcode 543. Diameter of Binary Tree

題目描述:找出二叉樹的最長直徑(也就是所以節點連成最長的路徑長度) 題目鏈接:Leetcode 543. Diameter of Binary Tree 題目思路:用到的就是經典的遞歸返回值的形式,不斷返回左子樹和右子樹的深度,然後過程中更新最長的路徑。 代碼如下 class Solution: def diameterOfBinaryTree(self, root): "
相關文章
相關標籤/搜索