DFS-PYTHON-CLEAN
CONCEPT IS SAME DIVIDE EACH CELL INTO 4 TRIANGLE AND TREAT EACH TRIANGLE AS A DIFFERENT UNIT AND DO THE SAME AS "COUNT NO. OF ISLAND"https://leetcode.com/proble
CONCEPT IS SAME DIVIDE EACH CELL INTO 4 TRIANGLE AND TREAT EACH TRIANGLE AS A DIFFERENT UNIT AND DO THE SAME AS "COUNT NO. OF ISLAND"[https://leetcode.com/problems/number-of-islands/](http://) \n```\nclass Solution:\n    def regionsBySlashes(self, grid: List[str]) -> int:\n        \n        def check(x,y,t):\n            if x>=0 and y>=0 and x<row and y<col and (x,y,t) not in visited:\n                return True\n            return False\n        \n        row,col=len(grid),len(grid[0])\n        visited=set()\n        \n        def dfs(r,c,t):\n            if check(r,c,t):\n                visited.add((r,c,t))\n                if t==1:\n                    dfs(r,c+1,3)# going right\n                elif t==2:\n                    dfs(r+1,c,0)# going down\n                elif t==3:\n                    dfs(r,c-1,1) # going back\n                elif t==0: \n                    dfs(r-1,c,2)# going up\n                if grid[r][c]!="/":\n                    dfs(r,c,t^1) #trick to traverse 0 to 1 or 3 to 2 and viceversa\n                if grid[r][c]!="\\\\":\n                    dfs(r,c,t^3)#trick to traverse 3 to 0 or 1 to 2 and viceversa\n        \n        cntofregion=0\n        for i in range(row):\n            for j in range(col):\n                for typ in range(4):\n                    if (i,j,typ) not in visited:\n                        dfs(i,j,typ)\n                        cntofregion+=1\n        return cntofregion                \n        \n```\n![image](https://assets.leetcode.com/users/images/8b05decd-f363-457f-9b36-ccd887223b39_1625253290.4811695.png)\n
['Python', 'Python3']