We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a865463 commit 0d38bc3Copy full SHA for 0d38bc3
docs/Leetcode_Solutions/Python/Summary/Union_Find/union_find.md
@@ -218,7 +218,6 @@ class UnionFind(object):
218
self.count = n
219
self.uf = [i for i in range(n)]
220
self.size = [1] * n # 每个联通分量的size
221
- self.rank = [1] * n
222
223
def find(self, x): # 判断节点所属于的组
224
while x != self.uf[x]:
@@ -231,9 +230,8 @@ class UnionFind(object):
231
230
y_root = self.find(y)
232
if x_root == y_root:
233
return
234
- if self.rank[x_root] < self.rank[y_root]:
+ if self.size[x_root] < self.size[y_root]:
235
x_root, y_root = y_root, x_root
236
- self.rank[x_root] += self.rank[y_root]
237
self.uf[y_root] = x_root
238
self.size[x_root] += self.size[y_root]
239
self.size[y_root] = 0
0 commit comments