LC: 1245. Tree Diameter

https://leetcode.com/problems/tree-diameter/

1245. Tree Diameter

Given an undirected tree, return its diameter: the number of edges in a longest path in that tree.

The tree is given as an array of edges where edges[i] = [u, v] is a bidirectional edge between nodes u and v. Each node has labels in the set {0, 1, ..., edges.length}.

Example 1:

Example 2:

Constraints:

  • 0 <= edges.length < 10^4

  • edges[i][0] != edges[i][1]

  • 0 <= edges[i][j] <= edges.length

  • The given edges form an undirected tree.

Last updated