Best Java Solution 1ms | Union Find Notes
\nclass Solution {\n    int[] parent;\n    int x,y;\n    int[] res;\n    public int[] findRedundantConnection(int[][] edges) {\n        int n = edges.length;\n 
```\nclass Solution {\n    int[] parent;\n    int x,y;\n    int[] res;\n    public int[] findRedundantConnection(int[][] edges) {\n        int n = edges.length;\n        parent = new int[n+1];\n        res = new int[2];\n        for(int i=1; i <= n; ++i){\n            parent[i] = i;\n        }\n        for(int i = 0; i < n;++i){\n            x = find_parent(edges[i][0]);\n            y = find_parent(edges[i][1]);\n            if(x == y){\n                res[0] = edges[i][0];\n                res[1] = edges[i][1];\n                break;\n            }\n            Union(x,y);\n        }\n        return res;\n    }\n    public void Union(int x, int y){\n        parent[x] = y;\n    }\n    \n    public int find_parent(int a){\n        if(a == parent[a]){\n            return a;\n        }\n        else{\n            return find_parent(parent[a]);\n        }\n    }\n}\n```\n![image](https://assets.leetcode.com/users/images/cfbe5b0b-d6f8-4c6c-ba64-87bf44534b97_1652287877.1792982.png)\n
['Union Find', 'Graph']