Skip to content

Commit c8485cd

Browse files
authored
Update Solution.java
1 parent 4f39980 commit c8485cd

File tree

1 file changed

+0
-6
lines changed
  • src/main/java/g1701_1800/s1743_restore_the_array_from_adjacent_pairs

1 file changed

+0
-6
lines changed

src/main/java/g1701_1800/s1743_restore_the_array_from_adjacent_pairs/Solution.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,18 @@ public int[] restoreArray(int[][] adjacentPairs) {
1515
if (adjacentPairs.length == 1) {
1616
return adjacentPairs[0];
1717
}
18-
1918
Map<Integer, List<Integer>> graph = new HashMap<>();
20-
2119
for (int[] pair : adjacentPairs) {
2220
graph.computeIfAbsent(pair[0], k -> new ArrayList<>()).add(pair[1]);
2321
graph.computeIfAbsent(pair[1], k -> new ArrayList<>()).add(pair[0]);
2422
}
25-
2623
int[] res = new int[graph.size()];
27-
2824
for (Map.Entry<Integer, List<Integer>> entry : graph.entrySet()) {
2925
if (entry.getValue().size() == 1) {
3026
res[0] = entry.getKey();
3127
break;
3228
}
3329
}
34-
3530
res[1] = graph.get(res[0]).get(0);
3631
for (int i = 2; i < res.length; i++) {
3732
for (int cur : graph.get(res[i - 1])) {
@@ -41,7 +36,6 @@ public int[] restoreArray(int[][] adjacentPairs) {
4136
}
4237
}
4338
}
44-
4539
return res;
4640
}
4741
}

0 commit comments

Comments
 (0)