![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode UnionFind
文章平均质量分 55
Leetcode中与UnionFind有关的题目
努利!奋斗!
这个作者很懒,什么都没留下…
展开
-
Leetcode 1584. Min Cost to Connect All Points (python)
Leetcode 1584. Min Cost to Connect All Points题目错误解法:解法:Minimum spanning tree题目错误解法:最开始以为通过判断加入的边的数量和被访问过的点的数量可以判断是不是符合条件了,其实这样是不成立的,可以举出很多反例class Solution(object): def minCostConnectPoints(self, points): """ :type points: List[Lis原创 2020-10-18 08:09:50 · 866 阅读 · 0 评论 -
根据距离求cluster
题目:解法:解法与上面说的思路一样import mathimport collectionsdef cal_dis(x1,y1,x2,y2): return math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))k = 7points = [(0,1),(0,2),(0,3),(0,4),(0,10),(0,11),(0,100),(0,101)]graph = collections.defaultdict(set)for i in rang原创 2020-09-20 09:30:10 · 397 阅读 · 0 评论 -
Leetcode 684. Redundant Connection (python)
Leetcode 684. Redundant Connection题目解法1:dfs解法2:unionfind题目解法1:dfs一次构建图,返回第一组成环的边。class Solution: def findRedundantConnection(self, edges: List[List[int]]) -> List[int]: def dfs(source,target): if source in seen:原创 2020-09-06 11:41:25 · 369 阅读 · 0 评论 -
Leetcode 305. Number of Islands II (python)
Leetcode 305. Number of Islands II题目:解法:hashmap题目:解法:hashmap这道题是number of islands的follow up,关于number of islands见另外一篇博客。这道题目的难点在于,原创 2020-09-06 10:14:22 · 875 阅读 · 0 评论