Leet Code Daily 2024-06-27 - Find Center of Star Graph
Code
class Solution {
public:
int findCenter(vector<vector<int>>& edges) {
unordered_set<int> nodes_with_edge;
for (const auto& edge : edges) {
for (const auto& node : edge) {
if (nodes_with_edge.contains(node)) {
return node;
}
nodes_with_edge.insert(node);
}
}
return -1;
}
};