1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/找出星型图的中心节点 [find-center-of-star-graph].html
2022-03-29 12:43:11 +08:00

34 lines
1.5 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>有一个无向的 <strong>星型</strong> 图,由 <code>n</code> 个编号从 <code>1</code><code>n</code> 的节点组成。星型图有一个 <strong>中心</strong> 节点,并且恰有 <code>n - 1</code> 条边将中心节点与其他每个节点连接起来。</p>
<p>给你一个二维整数数组 <code>edges</code> ,其中 <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> 表示在节点 <code>u<sub>i</sub></code><code>v<sub>i</sub></code> 之间存在一条边。请你找出并返回 <code>edges</code> 所表示星型图的中心节点。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2021/03/14/star_graph.png" style="width: 331px; height: 321px;" />
<pre>
<strong>输入:</strong>edges = [[1,2],[2,3],[4,2]]
<strong>输出:</strong>2
<strong>解释:</strong>如上图所示,节点 2 与其他每个节点都相连,所以节点 2 是中心节点。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>edges = [[1,2],[5,1],[1,3],[1,4]]
<strong>输出:</strong>1
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 <= n <= 10<sup>5</sup></code></li>
<li><code>edges.length == n - 1</code></li>
<li><code>edges[i].length == 2</code></li>
<li><code>1 <= u<sub>i,</sub> v<sub>i</sub> <= n</code></li>
<li><code>u<sub>i</sub> != v<sub>i</sub></code></li>
<li>题目数据给出的 <code>edges</code> 表示一个有效的星型图</li>
</ul>