class Solution {
public:
vector<int> findRedundantConnection(vector<vector<int>>& edges) {
int len = edges.size();
vector<int> parent(2000,0);
vector<int> ret;
for(int i = 0; i < parent.size(); ++i){
parent[i] = i;
}
/*auto completion*/
for(auto v : edges ){
int n1 = v[0], n2 = v[1];
while(n1 != parent[n1]) n1 = parent[n1];
while(n2 != parent[n2]) n2 = parent[n2];
if( n1 == n2 )
ret = v;
else{
parent[n2] = n1;
}
}
return ret;
}
};
684. Redundant Connection
最新推荐文章于 2021-12-03 03:36:27 发布