Union find python (general approach) beats 99%
Similar approach can be followed for \n\n1.  Number of Islands II\n2. Couples Holding Hands\n3. Most Stones Removed\n4. Redundant Connection\npython\nclass Unio
Similar approach can be followed for \n\n1. [ Number of Islands II](https://leetcode.com/problems/number-of-islands-ii/discuss/246928/Union-find-(general-approach))\n2. [Couples Holding Hands](https://leetcode.com/problems/couples-holding-hands/discuss/246929/Python-union-find-beats-100)\n3. [Most Stones Removed](https://leetcode.com/problems/most-stones-removed-with-same-row-or-column/discuss/246931/Python-union-find-(general-approach))\n4. [Redundant Connection](https://leetcode.com/problems/redundant-connection/discuss/246972/Union-find-python-(general-approach)-beats-99)\n```python\nclass UnionFind(object):\n    def __init__(self):\n        self.parents = {}\n    \n    def make_set(self, x):\n        self.parents[x] = x\n        \n    def find(self, x):\n        if x not in self.parents:\n            self.make_set(x)\n            return x\n        elif self.parents[x] == x:\n            return x\n        self.parents[x] = self.find(self.parents[x])\n        return self.parents[x]\n    \n    def union(self, x, y):\n        x_set = self.find(x)\n        y_set = self.find(y)\n        if x_set != y_set:\n            self.parents[x_set] = y_set\n            return True\n        return False\n\n\nclass Solution(object):\n    def findRedundantConnection(self, edges):\n        """\n        :type edges: List[List[int]]\n        :rtype: List[int]\n        """\n        n=len(edges)\n        uf = UnionFind()\n        for x, y in edges:\n            if not uf.union(x, y):\n                return ((x,y))\n```
[]