Class Solution
java.lang.Object
g0501_0600.s0543_diameter_of_binary_tree.Solution
543 - Diameter of Binary Tree.<p>Easy</p>
<p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>.</p>
<p>The <strong>length</strong> of a path between two nodes is represented by the number of edges between them.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/03/06/diamtree.jpg" alt="" /></p>
<p><strong>Input:</strong> root = [1,2,3,4,5]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> 3 is the length of the path [4,2,1,3] or [5,2,1,3].</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> root = [1,2]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Constraints:</strong></p>
<ul>
<li>The number of nodes in the tree is in the range <code>[1, 10<sup>4</sup>]</code>.</li>
<li><code>-100 <= Node.val <= 100</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
diameterOfBinaryTree
-