#1791
Easy Algorithms Find center of star graph
Graph Theory
86.6% acceptance
Feb 25, 2026
1979
182
There is an undirected star graph. You are given a 2D integer array edges. Return the center of the given star graph.
Solution
Rust
Time O(1)
Space O(1)
impl Solution {
pub fn find_center(edges: Vec<Vec<i32>>) -> i32 {
// The center appears in both the first and second edge
let e0 = &edges[0];
let e1 = &edges[1];
if e0[0] == e1[0] || e0[0] == e1[1] { e0[0] } else { e0[1] }
}
}