Skip to content

Commit e4fdee3

Browse files
authored
Update redundant-connection-ii.py
1 parent 94620c3 commit e4fdee3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Python/redundant-connection-ii.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def find_set(self, x):
1212

1313
def union_set(self, x, y):
1414
x_root, y_root = map(self.find_set, (x, y))
15-
if x_root == y_root or \
16-
y != y_root: # already has a father
15+
if x_root == y_root:
1716
return False
1817
self.set[y_root] = x_root
1918
return True
@@ -26,12 +25,12 @@ def findRedundantDirectedConnection(self, edges):
2625
:rtype: List[int]
2726
"""
2827
cand1, cand2 = None, None
29-
parents = {}
28+
parent = {}
3029
for edge in edges:
31-
if edge[1] not in parents:
32-
parents[edge[1]] = edge[0]
30+
if edge[1] not in parent:
31+
parent[edge[1]] = edge[0]
3332
else:
34-
cand1 = [parents[edge[1]], edge[1]]
33+
cand1 = [parent[edge[1]], edge[1]]
3534
cand2 = edge
3635

3736
union_find = UnionFind(len(edges)+1)

0 commit comments

Comments
 (0)