Guest User

Untitled

a guest
Mar 25th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. public class Solution {
  2. public int[] findRedundantConnection(int[][] edges) {
  3. int[] root = new int[edges.length + 1];
  4. Arrays.setAll(root, i -> i);
  5. for (int[] edge : edges) {
  6. if (root[edge[0]] == root[edge[1]]) {
  7. return edge;
  8. }
  9. int update = root[edge[1]];
  10. for (int i = 1; i < root.length; i++) {
  11. if (root[i] == update) {
  12. root[i] = root[edge[0]];
  13. }
  14. }
  15. }
  16. return null;
  17. }
  18. }
Add Comment
Please, Sign In to add comment