Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def solve(self, board: List[List[str]]) -> None:
- """
- Do not return anything, modify board in-place instead.
- """
- rows = len(board)
- cols = len(board[0])
- visited = set()
- def dfs(r, c):
- if r<0 or c<0 or c == cols or r == rows or board[r][c] == "X" or (r, c) in visited:
- return
- visited.add((r, c))
- dfs(r+1, c)
- dfs(r-1, c)
- dfs(r, c+1)
- dfs(r, c-1)
- return
- for r in range(rows):
- dfs(r, 0)
- dfs(r, cols-1)
- for c in range(cols):
- dfs(0, c)
- dfs(rows-1, c)
- for r in range(rows):
- for c in range(cols):
- if (r, c) not in visited:
- board[r][c] = "X"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement