In a N x N grid composed of 1 x 1 squares, each 1 x 1 square consists of a /, \, or blank space.  These characters divide the square into contiguous regions.
(Note that backslash characters are escaped, so a \ is represented as "\\".)
Return the number of regions.
Example 1:
Input:
[
  " /",
  "/ "
]
Output: 2
Explanation: The 2x2 grid is as follows:
Example 2:
Input:
[
  " /",
  "  "
]
Output: 1
Explanation: The 2x2 grid is as follows:
Example 3:
Input:
[
  "\\/",
  "/\\"
]
Output: 4
Explanation: (Recall that because \ characters are escaped, "\\/" refers to \/, and "/\\" refers to /\.)
The 2x2 grid is as follows:
Example 4:
Input:
[
  "/\\",
  "\\/"
]
Output: 5
Explanation: (Recall that because \ characters are escaped, "/\\" refers to /\, and "\\/" refers to \/.)
The 2x2 grid is as follows:
Example 5:
Input:
[
  "//",
  "/ "
]
Output: 3
Explanation: The 2x2 grid is as follows:
Note:
1 <= grid.length == grid[0].length <= 30
grid[i][j] is either '/', '\', or ' '.
class Solution:
    def regionsBySlashes(self, g: List[str]) -> int:
        
        n = len(g)
        
        grid = [[0]*(n*3) for j in range(n*3)]
        
        for i in range(n):
            
            for j in range(n):
                
                if g[i][j] == '/':
                    
                    grid[i*3][j*3+2] = 1
                    
                    grid[i*3+1][j*3+1] = 1
                    
                    grid[i*3+2][j*3] = 1
                    
                elif g[i][j] == '\\\\':
                    
                    grid[i*3][j*3] = 1
                    
                    grid[i*3+1][j*3+1] = 1
                    
                    grid[i*3+2][j*3+2] = 1
     
                    
        def dfs(i,j):
            
            grid[i][j] = 1
            
            for r in [(i+1,j), (i,j+1), (i-1,j), (i,j-1)]:
                
                xx,yy = r
                
                if xx < 0 or yy < 0 or xx >= len(grid) or yy >= len(grid[0]) or grid[xx][yy] == 1:
                    continue
                    
                dfs(xx,yy)
                
                
        count = 0
        
        for i in range(n*3):
            for j in range(n*3):
                
                if grid[i][j] == 0:
                    
                    dfs(i,j)
                    
                    count += 1
                    
        return count
class Solution:
    def regionsBySlashes(self, g: List[str]) -> int:
        
        n = len(g)
        
        grid = [[0]*(n*3) for j in range(n*3)]
        
        for i in range(n):
            
            for j in range(n):
                
                if g[i][j] == '/':
                    
                    grid[i*3][j*3+2] = 1
                    
                    grid[i*3+1][j*3+1] = 1
                    
                    grid[i*3+2][j*3] = 1
                    
                elif g[i][j] == '\\\\':
                    
                    grid[i*3][j*3] = 1
                    
                    grid[i*3+1][j*3+1] = 1
                    
                    grid[i*3+2][j*3+2] = 1
     
                    
        def dfs(i,j):
            
            grid[i][j] = 1
            
            for r in [(i+1,j), (i,j+1), (i-1,j), (i,j-1)]:
                
                xx,yy = r
                
                if xx < 0 or yy < 0 or xx >= len(grid) or yy >= len(grid[0]) or grid[xx][yy] == 1:
                    continue
                    
                dfs(xx,yy)
                
                
        count = 0
        
        for i in range(n*3):
            for j in range(n*3):
                
                if grid[i][j] == 0:
                    
                    dfs(i,j)
                    
                    count += 1
                    
        return count