Python Union Find solution with comments (easy to understand)
\nclass UnionFind:\n    def __init__(self, n):\n        self.parent = [i for i in range(n)]\n        \n    def find(self, x):\n        if self.parent[x] != x:\n
```\nclass UnionFind:\n    def __init__(self, n):\n        self.parent = [i for i in range(n)]\n        \n    def find(self, x):\n        if self.parent[x] != x:\n            self.parent[x] = self.find(self.parent[x])\n        return self.parent[x]\n    \n    def union(self, a, b):\n        self.parent[self.find(b)] = self.find(a)\n\nclass Solution:\n    def regionsBySlashes(self, grid: List[str]) -> int:\n        n = len(grid)\n        # Divide each square into 4 triangles\n        uf = UnionFind(4 * n * n) \n        \n        for row in range(n):\n            for col in range(n):\n                cell = grid[row][col]\n                index = 4 * (row * n + col) \n                \n                # When there are no lines in the square\n                if cell == \' \':\n                    uf.union(index+0, index+1)\n                    uf.union(index+1, index+2)\n                    uf.union(index+2, index+3)\n                # When there\'s a bottom left - top right diagonal line dividing the square\n                if cell == \'/\':\n                    uf.union(index+0, index+3)\n                    uf.union(index+1, index+2)\n                # When there\'s a top left - bottom right diagonal line dividing the square\n                if cell == \'\\\\\':\n                    uf.union(index+2, index+3)\n                    uf.union(index+0, index+1)\n                # Connecting a square with square below it\n                if row < n - 1:\n                    uf.union(index+2, (index + 4*n) + 0)\n                # Connecting a square with right side square\n                if col < n - 1:\n                    uf.union(index+1, (index + 4) + 3)\n                    \n        output = 0\n        for i in range(4*n*n):\n            if uf.find(i) == i:\n                output += 1\n        return output\n```
['Union Find', 'Python', 'Python3']