@@ -63,10 +63,10 @@ Output: [1,4]
6363``` python
6464class Solution :
6565 def __init__ (self ):
66- self .fathers = None
66+ self .parent = None
6767
6868 def findRedundantConnection (self , edges : List[List[int ]]) -> List[int ]:
69- self .fathers = list (range (len (edges) + 1 ))
69+ self .parent = list (range (len (edges) + 1 ))
7070
7171 for x, y in edges:
7272 if self .same_root(x, y):
@@ -78,15 +78,15 @@ class Solution:
7878 root_x = self .find_root(x)
7979 root_y = self .find_root(y)
8080
81- self .fathers [root_y] = root_x # Error-prone point
81+ self .parent [root_y] = root_x # Error-prone point
8282
8383 def find_root (self , x ):
84- if x == self .fathers [x]:
84+ if x == self .parent [x]:
8585 return x
8686
87- self .fathers [x] = self .find_root(self .fathers [x])
87+ self .parent [x] = self .find_root(self .parent [x])
8888
89- return self .fathers [x]
89+ return self .parent [x]
9090
9191 def same_root (self , x , y ):
9292 return self .find_root(x) == self .find_root(y)
@@ -95,13 +95,13 @@ class Solution:
9595## Java
9696``` java
9797class Solution {
98- private int [] fathers ;
98+ private int [] parent ;
9999
100100 public int [] findRedundantConnection (int [][] edges ) {
101- fathers = new int [edges. length + 1 ];
101+ parent = new int [edges. length + 1 ];
102102
103- for (var i = 0 ; i < fathers . length; i++ ) {
104- fathers [i] = i;
103+ for (var i = 0 ; i < parent . length; i++ ) {
104+ parent [i] = i;
105105 }
106106
107107 for (var edge : edges) {
@@ -119,17 +119,17 @@ class Solution {
119119 int rootX = findRoot(x);
120120 int rootY = findRoot(y);
121121
122- fathers [rootY] = rootX; // Error-prone point 1
122+ parent [rootY] = rootX; // Error-prone point 1
123123 }
124124
125125 private int findRoot (int x ) {
126- if (x == fathers [x]) {
126+ if (x == parent [x]) {
127127 return x;
128128 }
129129
130- fathers [x] = findRoot(fathers [x]); // Error-prone point 2
130+ parent [x] = findRoot(parent [x]); // Error-prone point 2
131131
132- return fathers [x];
132+ return parent [x];
133133 }
134134
135135 private boolean sameRoot (int x , int y ) {
@@ -144,7 +144,7 @@ class Solution {
144144public:
145145 vector<int > findRedundantConnection(vector<vector<int >>& edges) {
146146 for (auto i = 0; i <= edges.size(); i++) {
147- fathers .push_back(i);
147+ parent .push_back(i);
148148 }
149149
150150 for (auto& edge : edges) {
@@ -159,23 +159,23 @@ public:
159159 }
160160
161161private:
162- vector<int > fathers ;
162+ vector<int > parent ;
163163
164164 void unite(int x, int y) {
165165 int root_x = findRoot(x);
166166 int root_y = findRoot(y);
167167
168- fathers [root_y] = root_x; // Error-prone point 1
168+ parent [root_y] = root_x; // Error-prone point 1
169169 }
170170
171171 int findRoot(int x) {
172- if (x == fathers [x]) {
172+ if (x == parent [x]) {
173173 return x;
174174 }
175175
176- fathers [x] = findRoot(fathers [x]); // Error-prone point 2
176+ parent [x] = findRoot(parent [x]); // Error-prone point 2
177177
178- return fathers [x];
178+ return parent [x];
179179 }
180180
181181 bool sameRoot(int x, int y) {
@@ -186,12 +186,12 @@ private:
186186
187187## JavaScript
188188```javascript
189- let fathers
189+ let parent
190190
191191var findRedundantConnection = function(edges) {
192- fathers = []
192+ parent = []
193193 for (let i = 0; i <= edges.length; i++) {
194- fathers .push(i)
194+ parent .push(i)
195195 }
196196
197197 for (let [x, y] of edges) {
@@ -209,17 +209,17 @@ function unite(x, y) {
209209 rootX = findRoot(x)
210210 rootY = findRoot(y)
211211
212- fathers [rootY] = rootX // Error-prone point 1
212+ parent [rootY] = rootX // Error-prone point 1
213213}
214214
215215function findRoot(x) {
216- if (x == fathers [x]) {
216+ if (x == parent [x]) {
217217 return x
218218 }
219219
220- fathers [x] = findRoot(fathers [x]) // Error-prone point 2
220+ parent [x] = findRoot(parent [x]) // Error-prone point 2
221221
222- return fathers [x]
222+ return parent [x]
223223}
224224
225225function sameRoot(x, y) {
@@ -231,14 +231,14 @@ function sameRoot(x, y) {
231231``` c#
232232public class Solution
233233{
234- int [] fathers ;
234+ int [] parent ;
235235
236236 public int [] FindRedundantConnection (int [][] edges )
237237 {
238- fathers = new int [edges .Length + 1 ];
238+ parent = new int [edges .Length + 1 ];
239239
240- for (int i = 0 ; i < fathers .Length ; i ++ )
241- fathers [i ] = i ;
240+ for (int i = 0 ; i < parent .Length ; i ++ )
241+ parent [i ] = i ;
242242
243243 foreach (int [] edge in edges )
244244 {
@@ -258,17 +258,17 @@ public class Solution
258258 int rootX = findRoot (x );
259259 int rootY = findRoot (y );
260260
261- fathers [rootY ] = rootX ; // Error-prone point 1
261+ parent [rootY ] = rootX ; // Error-prone point 1
262262 }
263263
264264 int findRoot (int x )
265265 {
266- if (x == fathers [x ])
266+ if (x == parent [x ])
267267 return x ;
268268
269- fathers [x ] = findRoot (fathers [x ]); // Error-prone point 2
269+ parent [x ] = findRoot (parent [x ]); // Error-prone point 2
270270
271- return fathers [x ];
271+ return parent [x ];
272272 }
273273
274274 bool sameRoot (int x , int y )
@@ -280,12 +280,12 @@ public class Solution
280280
281281## Go
282282``` go
283- var fathers []int
283+ var parent []int
284284
285285func findRedundantConnection (edges [][]int ) []int {
286- fathers = make ([]int , len (edges) + 1 )
287- for i := 0 ; i < len (fathers ); i++ {
288- fathers [i] = i
286+ parent = make ([]int , len (edges) + 1 )
287+ for i := 0 ; i < len (parent ); i++ {
288+ parent [i] = i
289289 }
290290
291291 for _ , edge := range edges {
@@ -303,17 +303,17 @@ func unite(x, y int) {
303303 rootX := findRoot (x)
304304 rootY := findRoot (y)
305305
306- fathers [rootY] = rootX // Error-prone point 1
306+ parent [rootY] = rootX // Error-prone point 1
307307}
308308
309309func findRoot (x int ) int {
310- if x == fathers [x] {
310+ if x == parent [x] {
311311 return x
312312 }
313313
314- fathers [x] = findRoot (fathers [x]) // Error-prone point 2
314+ parent [x] = findRoot (parent [x]) // Error-prone point 2
315315
316- return fathers [x]
316+ return parent [x]
317317}
318318
319319func sameRoot (x , y int ) bool {
@@ -324,8 +324,8 @@ func sameRoot(x, y int) bool {
324324## Ruby
325325``` ruby
326326def find_redundant_connection (edges )
327- @fathers = []
328- (0 ..edges.size).each { |i | @fathers << i }
327+ @parent = []
328+ (0 ..edges.size).each { |i | @parent << i }
329329
330330 edges.each do |edge |
331331 if same_root(edge[0 ], edge[1 ])
@@ -340,17 +340,17 @@ def unite(x, y)
340340 root_x = find_root(x)
341341 root_y = find_root(y)
342342
343- @fathers [root_y] = root_x # Error-prone point 1
343+ @parent [root_y] = root_x # Error-prone point 1
344344end
345345
346346def find_root (x )
347- if x == @fathers [x]
347+ if x == @parent [x]
348348 return x
349349 end
350350
351- @fathers [x] = find_root(@fathers [x]) # Error-prone point 2
351+ @parent [x] = find_root(@parent [x]) # Error-prone point 2
352352
353- @fathers [x]
353+ @parent [x]
354354end
355355
356356def same_root (x , y )
0 commit comments