Find Center of Star Graph

Easy

Topics
Graph

You are given an undirected star graph of n nodes labeled 1..n. A star graph has one center node connected to every other node, and no other edges. Given its edges, return the label of the center node.

Example 1

Input:  n = 3, edges = [[1,2],[2,3]]
Output: 2

Example 2

Input:  n = 4, edges = [[4,1],[4,2],[4,3]]
Output: 4

Constraints

  • 3 <= n <= 10^5
  • The given graph is a valid star graph.
Run ⌘' · Submit ⌘⏎