543_Diameter of Binary Tree
543. Diameter of Binary Tree
Level: easy
Tag: tree
Question
Example 1
Solution: recursive
If root.val is in the longest path, the best diameter will be depth(root.left) + depth(root.right)
. So need to calculate depth(root.left)
and depth(root.right)
. At the same time, update best diameter with the diameter of root.left
and root.right.
Last updated