Skip to content

Commit bb078ca

Browse files
use index as its ID
1 parent 8372638 commit bb078ca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

MEDIUM/src/medium/GraphValidTree.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class GraphValidTree {
99

1010
public boolean validTree(int n, int[][] edges){
1111
int[] nums = new int[n];
12-
Arrays.fill(nums, -1);
12+
for(int i =0; i < n; i++) nums[i] = i;
1313

1414
for(int i = 0; i < edges.length; i++){
1515
int x = find(nums, edges[i][0]);
@@ -25,7 +25,7 @@ public boolean validTree(int n, int[][] edges){
2525
}
2626

2727
int find(int[] nums, int i){
28-
if(nums[i] == -1) return i;
28+
if(nums[i] == i) return i;
2929
return find(nums, nums[i]);
3030
}
3131
}

0 commit comments

Comments
 (0)