_1791

package
v0.0.0-...-5ea41ec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 0 Imported by: 0

README

找出星型图的中心节点

有一个无向的 星型 图,由 n 个编号从 1n 的节点组成。星型图有一个 中心 节点,并且恰有 n - 1 条边将中心节点与其他每个节点连接起来。

给你一个二维整数数组 edges ,其中 edges[i] = [ui, vi] 表示在节点 uivi 之间存在一条边。请你找出并返回 edges 所表示星型图的中心节点。

示例 1:

``` 输入:edges = [[1,2],[2,3],[4,2]] 输出:2 解释:如上图所示,节点 2 与其他每个节点都相连,所以节点 2 是中心节点。


**示例 2:**

输入:edges = [[1,2],[5,1],[1,3],[1,4]] 输出:1




**提示:**

* `3 <= n <= 105`
* `edges.length == n - 1`
* `edges[i].length == 2`
* `1 <= ui, vi <= n`
* `ui != vi`
* 题目数据给出的 `edges` 表示一个有效的星型图

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL