并查集实现细节影响用例通过

内容概览
本文探讨了在并查集实现中,将find函数中的while循环条件从self.father[root]改为self.father[root]!=None后,特定用例能够通过的原因。通过代码示例详细解释了这一改动的必要性和影响。
Tenacity
2024-08-08 20:07
赞2评论6
. - 力扣(LeetCode)「加入星球后可见」 用并查集实现时为什么把 def find(self,x):     root = x     while self.father[root] :       root = self.father[root] 中的while self.father[root] :改成while self.father[root]!=None: 用例[[1,1,1],[1,1,1],[1,1,1]]就可以过 代码如下: class...

英雄算法联盟

星球已运营 4 年零 211 天

累计超过  5700+  位成员加入

18小时前

最近更新

51000+

内容数

进入星球主页