1791 - Find Center of Star Graph

 JAVA

class Solution {
    public int findCenter(int[][] edges) {
        int a = edges[0][0], b = edges[0][1];
        int c = edges[1][0], d = edges[1][1];
        return a == c || a == d ? a : b;
    }
}

C++

class Solution {
public:
    int findCenter(vector<vector<int>>& E) {
        return E[0][0] == E[1][0] || E[0][0] == E[1][1] ? E[0][0] : E[0][1];
    }
};

Comments