Find Center of Star Graph

Given the edges of a star graph, return the center node. Pattern focus: Degree. In a star graph, the center is the unique node with degree n - 1.

Input Format

edges = edge list of a star graph

Output Format

label of the center node

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • edges must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

edges = [[1,2],[2,3],[4,2]]

Output:

2

Explanation:

Node 2 appears in every edge.

Example 2:

Input:

edges = [[1,2],[5,1],[1,3],[1,4]]

Output:

1

Explanation:

Node 1 has the highest degree.

Loading...
Find Center of Star Graph - Graph Fundamentals