Original title link: Leetcode 1791. Find the central node of the star graph
class Solution {
public:
int findCenter(vector<vector<int>>& edges) {
int res=0,cnt=0;
int n=edges.size()+1;
vector<int> degree(n+1);
for(auto x:edges){
int a=x[0],b=x[1];
degree[a]++; degree[b]++;
}
for(int i=1;i<=n;i++)
{
if(degree[i]==n-1) return i;
}
return res;
}
};