In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to achieve the minimum height tree in Java". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to achieve the minimum height tree with Java"!
Title requirement
A tree is an undirected graph in which any two vertices are connected by only one path. In other words, any connected graph without a simple loop is a tree.
Give you a tree with n nodes, marked 0 to n-1. Given the number n and an edges list with n-1 undirected edges (each edge is a pair of labels), where edges [I] = [ai, bi] indicates that there is an undirected edge between the nodes ai and bi in the tree.
You can select any node in the tree as the root. When node x is selected as the root node, the height of the result tree is set to h. Among all possible trees, the tree with the lowest height (that is, min (h)) is called the minimum height tree.
Please find all the minimum height trees and return their root node label list in any order.
The height of the tree is the number of the longest downward path between the root node and the leaf node.
Example 1:
Input: n = 4, edges = [[1Jing 0], [1BI 2], [1BI 3]]
Output: [1]
Explanation: as shown in the figure, when the root is a node labeled 1, the height of the tree is 1, which is the only minimum height tree.
Example 2:
Input: n = 6, edges = [3Jing 0], [3jue 1], [3JEI 2], [3Jing 4], [5Jing 4]]
Output: [3pd4]
Tip:
one
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.