Find Center of Star Graph LeetCode solution in Python
1class Solution:2def findCenter(self, edges: List[List[int]]) -> int:3"""From the Constraints: A valid STAR GRAPH is confirmed.4That means the center will be common to every edges.5Therefore we can get the center by comparing only first 2 elements"""67for i in range(1):89# Check if first element of first edge mathches with any element of second edges1011if edges[i][0] == edges[i + 1][0] or edges[i][0] == edges[i + 1][1]:12return edges[i][0]1314# Otherwise second element of first edge will be the answer15else:16return edges[i][1]