class Solution {
public:
int findCenter(vector<vector<int>>& edges) {
int n=edges.size();
unordered_map<int, int>m;
for(int i=0;i<n;i++)
{
m[edges[i][0]]++;
m[edges[i][1]]++;
}
int ans=0;
for(auto x:m)
{
if(x.second==n)
{
ans=x.first;
break;
}
}
return ans;
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter