(self, board)
| 1 | class Solution(object): |
| 2 | def solve(self, board): |
| 3 | # https://discuss.leetcode.com/topic/22503/some-tips-for-python-code |
| 4 | if not board: |
| 5 | return |
| 6 | height, width = len(board), len(board[0]) |
| 7 | leakWall = self.buildLeakWall(board) |
| 8 | while leakWall: |
| 9 | i, j = leakWall.pop() |
| 10 | if 0 <= i < height and 0 <= j < width: |
| 11 | if board[i][j] == "O": |
| 12 | board[i][j] = "S" |
| 13 | leakWall += (i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1) |
| 14 | for i in range(height): |
| 15 | for j in range(width): |
| 16 | board[i][j] = "O" if board[i][j] == "S" else "X" |
| 17 | |
| 18 | def buildLeakWall(self, board): |
| 19 | leakWall, height, width = [], len(board), len(board[0]) |
nothing calls this directly
no test coverage detected