#1791
Find Center of Star Graph
newbie · 110 · lc easy +12 · verified · 86.6% accepted · 1,980 likes · top 98%
Description
An undirected star graph with n nodes has one center connected to all others by exactly n - 1 edges. Given edges[i] = [ui, vi], return the center node.
Example 1:
Input: edges = [[1,2],[2,3],[4,2]]
Output: 2
Explanation: As shown in the figure above, node 2 is connected to every other node, so 2 is the center.
Example 2:
Input: edges = [[1,2],[5,1],[1,3],[1,4]]
Output: 1
Code
1
2
3