Skip to content

Commit 0d38bc3

Browse files
authored
Update union_find.md
1 parent a865463 commit 0d38bc3

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

docs/Leetcode_Solutions/Python/Summary/Union_Find/union_find.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ class UnionFind(object):
218218
self.count = n
219219
self.uf = [i for i in range(n)]
220220
self.size = [1] * n # 每个联通分量的size
221-
self.rank = [1] * n
222221

223222
def find(self, x): # 判断节点所属于的组
224223
while x != self.uf[x]:
@@ -231,9 +230,8 @@ class UnionFind(object):
231230
y_root = self.find(y)
232231
if x_root == y_root:
233232
return
234-
if self.rank[x_root] < self.rank[y_root]:
233+
if self.size[x_root] < self.size[y_root]:
235234
x_root, y_root = y_root, x_root
236-
self.rank[x_root] += self.rank[y_root]
237235
self.uf[y_root] = x_root
238236
self.size[x_root] += self.size[y_root]
239237
self.size[y_root] = 0

0 commit comments

Comments
 (0)