当前位置:网站首页>leetcode684. Redundant connection (medium)
leetcode684. Redundant connection (medium)
2022-06-11 16:15:00 【Heavy garbage】



Ideas : Union checking set
When connectivity is found , Is the last edge ( Because this edge is the last edge of the ring , So when connectivity is found, it is ans)
class Solution {
public:
int father[1005];
void unite(int u, int v) {
int fau = findfather(u);
int fav = findfather(v);
if(fau != fav) father[fau] = fav;
}
int findfather(int m) {
if (father[m] == m) return m;
return father[m] = findfather(father[m]);
}
vector<int> findRedundantConnection(vector<vector<int>>& edges) {
for (int i = 1; i < 1005; ++i) {
father[i] = i;
}
for (auto& a : edges) {
int first = a[0], second = a[1];
if (findfather(first) == findfather(second)) return a;
unite(a[0], a[1]);
}
return {
};
}
};
边栏推荐
- AutoRunner自动化测试工具如何创建项目-Alltesting|泽众云测试
- How to predict SQL statement query time?
- 3000 words to teach you how to use mot
- 项目经理如何击退被工作汇报支配的恐惧感?
- AI tool for cutting-edge technology exploration: analog detection
- PyQt5 使QPlainTextEdit控件支持行号显示
- Pyqt5 enables the qplaintextedit control to support line number display
- Take you in-depth understanding of AGC cloud database
- Enterprise purchase, sales and inventory management system based on SSM framework [source code + database + design]
- [LeetCode每日一题] |686.重复叠加字符串匹配
猜你喜欢

Using cloud DB to build app quick start - quick application

Discussion on opengauss parallel decoding

Cloud data management will break the island of storage and the island of team

Collection | can explain the development and common methods of machine learning!

(OJ assignment of Hunan University of science and Technology) problem g: pattern matching of strings

postgresql启动过程

Opengauss database JDBC environment connection configuration (eclipse)

Pyqt5 enables the qplaintextedit control to support line number display

Factory calibrated gravity: working principle and installation position of carbon monoxide sensor, calibration standard description

干掉 Swagger UI,这款神器更好用、更高效!
随机推荐
Take you in-depth understanding of AGC cloud database
最近7天,最近10天,最近90天时间处理逻辑
Using cloud DB to build app quick start - quick application
【剑指Offer】21.调整数组顺序使奇数位于偶数前面
Golang map basic operations
PostgreSQL startup process
Understand the dense support functions / stored procedures of opengauss
Code farming essential SQL tuning (Part 1)
How to optimize the performance of compose? Find the answer through "underlying principles" | developers say · dtalk
减肥期间可以吃肉吗?会胖吗?
leetcode785. 判断二分图(中等)
AI function of cutting-edge technology exploration: slow SQL discovery
Collect | thoroughly understand the meaning and calculation of receptive field
Operation guide | how to select a collector on moonbeam and Moonriver
Factory calibrated gravity: working principle and installation position of carbon monoxide sensor, calibration standard description
Laravel8 implementation of sign in function
Code farming essential SQL tuning (Part 2)
Customized thread communication (lock) of JUC
postgresql启动过程
laravel 8 使用passport 进行Auth验证及颁发token