https://leetcode.com/problems/redundant-connection/description/

Use map to do Union Find.

class Solution {
public:
vector<int> findRedundantConnection(vector<vector<int>>& edges) {
unordered_map<int,int> parent;
for (const auto& e : edges) {
int p = findParent(parent, e[]);
int c = findParent(parent, e[]);
if (p == c)
return e;
parent[c] = p;
}
return vector<int>();
}
int findParent(unordered_map<int,int>& parents, int child) {
while (parents.count(child))
child = parents[child];
return child;
}
};

684. Redundant Connection的更多相关文章

  1. LN : leetcode 684 Redundant Connection

    lc 684 Redundant Connection 684 Redundant Connection In this problem, a tree is an undirected graph ...

  2. [LeetCode] 684. Redundant Connection 冗余的连接

    In this problem, a tree is an undirected graph that is connected and has no cycles. The given input ...

  3. leetcode 684. Redundant Connection

    We are given a "tree" in the form of a 2D-array, with distinct values for each node. In th ...

  4. LeetCode 684. Redundant Connection 冗余连接(C++/Java)

    题目: In this problem, a tree is an undirected graph that is connected and has no cycles. The given in ...

  5. 【LeetCode】684. Redundant Connection 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 并查集 日期 题目地址:https://leetco ...

  6. [LeetCode] 685. Redundant Connection II 冗余的连接之 II

    In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) f ...

  7. Leetcode之并查集专题-684. 冗余连接(Redundant Connection)

    Leetcode之并查集专题-684. 冗余连接(Redundant Connection) 在本问题中, 树指的是一个连通且无环的无向图. 输入一个图,该图由一个有着N个节点 (节点值不重复1, 2 ...

  8. [LeetCode] Redundant Connection 冗余的连接

    In this problem, a tree is an undirected graph that is connected and has no cycles. The given input ...

  9. [LeetCode] Redundant Connection II 冗余的连接之二

    In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) f ...

随机推荐

  1. 有趣的 验证JS只能输入正整数

    <html> <head> <title>只能输入正整数</title> </head> <body> 兑换数量:<inp ...

  2. C# 多线程之线程池

    线程池System.Threading.ThreadPool,可用于发送工作项.处理异步I/O.代表其它线程等待以及处理计时器.基本用法: public void Main() { ThreadPoo ...

  3. Javascript学习笔记-一些关键点

    Javascript学习笔记-一些关键点 Table of Contents 1. 调试 2. == vs === 3. 两种函数声明 4. 技术感悟 1 调试 现在的主流浏览器都提供了开发者模式,可 ...

  4. spring boot 监控与管理(actuator)

    Spring POMs 中提供了一个特殊的依赖模块,即spring-boot-starter-actuator,我们只需要在我们的POM中添加依赖即可 <!-- 监控 管理 --> < ...

  5. 响应式及Bootstrap

    一丶CSS3的@media 查询 使用 @media 查询,你可以针对不同的屏幕大小定义不同的样式. @media 可以针对不同的屏幕尺寸设置不同的样式,特别是如果你需要设置设计响应式的页面,@med ...

  6. input和textarea修改placeholder颜色和字号

    方式1因为每个浏览器的CSS选择器都有所差异,所以需要针对每个浏览器做单独的设定(可以在冒号前面写input和textarea).::-webkit-input-placeholder { /* We ...

  7. unicode字符和多字节字符的相互转换接口

    作者:朱金灿 来源:http://blog.csdn.net/clever101 发现开源代码的可利用资源真多,从sqlite3的源码中抠出了几个字符转换接口,稍微改造下了发现还挺好用的.下面是实现代 ...

  8. Android-->RxJava2更新体验

    截止日前最新版2017-3-15: RxJava compile ‘io.reactivex:rxjava:’ compile ‘io.reactivex:rxandroid:’ RxJava2 co ...

  9. ShopNC B2B2C多用户商城网站系统源码

    直接正常安装就行哦 注意有服务器的安装可以更下安装时间的长度 也就是说进行跳转的 如果时间太少 这样会安装不成 数据导入不完成 所以就会安装不成功安装好后打开data\config\config.in ...

  10. log4j 配置文件 (XML/.properties)

    xml: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configurat ...