Find Center of Star Graph

easy graph

Problem

Given the edges of an undirected star graph, return its center node.

Inputedges = [[1,2],[2,3],[4,2]]
Output2
Node 2 appears in every edge.

def find_center(edges):
    a, b = edges[0]
    c, d = edges[1]
    return a if a == c or a == d else b
function findCenter(edges) {
  const [a, b] = edges[0], [c, d] = edges[1];
  return a === c || a === d ? a : b;
}
class Solution {
    public int findCenter(int[][] edges) {
        return edges[0][0] == edges[1][0] || edges[0][0] == edges[1][1] ? edges[0][0] : edges[0][1];
    }
}
int findCenter(vector<vector<int>>& edges) {
    return edges[0][0] == edges[1][0] || edges[0][0] == edges[1][1] ? edges[0][0] : edges[0][1];
}
Time: O(1) Space: O(1)