while (!leafNodeQueue.isEmpty()) { minHeightRootList.clear(); for (inti= leafNodeQueue.size(); i > 0; i--) { minHeightRootList.add(leafNodeQueue.poll()); }
for (int root : minHeightRootList) { for (int to : nodeToNodeSetMap.get(root)) { degrees[to]--; // 切断与当前节点连接的边 if (degrees[to] == 1) { // 邻接节点是叶子节点 leafNodeQueue.offer(to); } } } }