Skip to main content

1791. Find Center of Star Graph

class Solution {
public:
int findCenter(vector<vector<int>>& edges)
{
vector<int> first = edges[0], second = edges[1];
return (first[0] == second[0] || first[0] == second[1]) ? first[0] : first[1];
}
};
  • T: O(1)O(1)
  • S: O(1)O(1)