1791. Find Center of Star Graph Easy
1/**
2 * [1791] Find Center of Star Graph
3 *
4 * There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.
5 * You are given a 2D integer array edges where each edges[i] = [ui, vi] indicates that there is an edge between the nodes ui and vi. Return the center of the given star graph.
6 *
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2021/02/24/star_graph.png" style="width: 331px; height: 321px;" />
9 * Input: edges = [[1,2],[2,3],[4,2]]
10 * Output: 2
11 * Explanation: As shown in the figure above, node 2 is connected to every other node, so 2 is the center.
12 *
13 * Example 2:
14 *
15 * Input: edges = [[1,2],[5,1],[1,3],[1,4]]
16 * Output: 1
17 *
18 *
19 * Constraints:
20 *
21 * 3 <= n <= 10^5
22 * edges.length == n - 1
23 * edges[i].length == 2
24 * 1 <= ui, vi <= n
25 * ui != vi
26 * The given edges represent a valid star graph.
27 *
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/find-center-of-star-graph/
32// discuss: https://leetcode.com/problems/find-center-of-star-graph/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37 pub fn find_center(edges: Vec<Vec<i32>>) -> i32 {
38 0
39 }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_1791() {
50 }
51}
52
Back
© 2025 bowen.ge All Rights Reserved.